L
L
lugger2015-03-17 11:36:58
Programming
lugger, 2015-03-17 11:36:58

Is it possible to learn to quickly understand someone else's code?

Very often I hear about such a skill as "the ability to quickly understand someone else's code." But at the sight of someone else's code, my brain boils and tends to sleep. Especially any javascript is generally a tin. Now I'm analyzing - in one file, the creation of objects through closures, through new and through Object.create. What for? Show knowledge of the language?
The main thing when applying for a job is sure to be asked about patterns, OOP, etc. And if you look into the code - sorry, it makes you want to puke. In one class, a bunch of methods, one line each, in another, each method has thousands of lines. Every collective farm as best they can. Worst of all, most of the code has no deep meaning - just crutches and quick fixes of minor bugs, done "as it happened". And how to understand it?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey, 2015-03-17
Protko @Fesor

Now I'm analyzing - in one file, the creation of objects through closures, through new and through Object.create. What for?

Creating an object through a closure is a module. It is necessary because there are no access modifiers in JS and everything private should be hidden in an isolated scope. This is a template.
Creating an object through new - how do you create objects? Don't use objects at all?
Object.create - this is already used for inheritance. Yes, of course, if you arm yourself with some kind of ES6, JS itself or ES6 - ES5 translators will do everything. But you need to know about it.
How to understand someone else's code? You need to be able to write your own to get started. The problems you describe are solved by periodic code reviews, etc. And writing shitty code is just as popular among front-end developers as it is among other developers. Perhaps only in the PHP community the percentage of shit code is higher. This is the problem of lack of education and understanding of those same patterns, etc. Memorize for an interview and all.

S
Saboteur, 2015-03-17
@saboteur_kiev

That's why they ask about patterns, because they're tired of raking someone else's redneck code.

O
OnYourLips, 2015-03-17
@OnYourLips

Now I'm analyzing - in one file, the creation of objects through closures, through new and through Object.create. What for? Show knowledge of the language?

Don't show, but apply.
Because the above reduces the complexity of working with the code.
Therefore, if you want to learn how to read code, you need to learn the language properly.

M
Maxim Gavrilov, 2015-03-17
@thestump

But at the sight of someone else's code, my brain boils and tends to sleep. Especially any javascript is generally a tin.

Brains are boiling - good for convolutions! Work with a boiling brain.
Take a look at your code, look at your crutches and quick fixes (I have never heard this from programmers pushing always clean code), and then go to strangers. Look at your own so that there will be less tantrums later. What gave in is and work. You won’t rewrite the entire project for the sake of a small block: you inserted it and went on.
Read about refactoring, and also the Perfect Code book.

S
SouthPark, 2021-12-28
@SouthPark

Here you will figure it out in a month, another problem, you sit scratching your head from where your legs are and what you thought up there a month ago. What an alien nafik, those managers go far through the forest, or let them negotiate with the old developers!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question