DEV Community

loading...

Discussion on: Most effective and simplest way to write readable code.

Collapse
lluismf profile image
LluĂ­s Josep MartĂ­nez

No shit Sherlock 😂😂

Collapse
andy profile image
Andy Zhao (he/him)

I don't think everyone knows how to refactor or write readable code, especially if they're a beginner. Let's not assume, yeah?

Collapse
lluismf profile image
LluĂ­s Josep MartĂ­nez

Fair enough. But you should take into account that this kind of click bait titles do not help your web. I expect a bit more.

Thread Thread
girish3 profile image
Girish Budhwani Author

I do wrote in the title that its the simplest way. I guess you are the only prey ;)

Collapse
girish3 profile image
Girish Budhwani Author • Edited

I know 😃 but mostly its not followed through.

Collapse
lluismf profile image
LluĂ­s Josep MartĂ­nez

In my experience it's followed most of the times, when it's necessary of course not blindly. In your example the original code is simple and very well structured. Putting a couple of lines of code in a method that is not reused outside this class is a bit extreme. But that's just me :-)

Thread Thread
girish3 profile image
Girish Budhwani Author

Example I used is just a snippet. The init() method earlier actually spanned 1000s of lines. And the extra line I have put between each set of logic is so that its easy to follow.

Thread Thread
lluismf profile image
LluĂ­s Josep MartĂ­nez

If a method has 1000s of lines then it's definitely a nightmare. But moving every 2/3 lines to a method will only make it worse. You'll end up with hundreds of methods. You need another kind of refactoring, perhaps creating multiple classes with different responsibilities.

Thread Thread
girish3 profile image
Girish Budhwani Author

Yeah we actually did the refactoring and created multiple classes and methods.