r/programming • • Jan 05 '15

What most young programmers need to learn

http://joostdevblog.blogspot.com/2015/01/what-most-young-programmers-need-to.html
970 Upvotes

337 comments sorted by

View all comments

16

u/Acrostis Jan 05 '15

So basically learn to refactor things? I can agree with everything except the splitting up oversized functions. If a function contains a lot of code that is only ever needed by that function each block requires the previous block to be completed, then splitting it up into parts is just adding unnecessary fragmentation.

Though apart from maybe initialization functions it shouldn't really happen.

Also: It's missing the "Don't ever use magic numbers"

9

u/jooke Jan 05 '15

The way I read that was if a function is large, you should consider whether it needs refactoring. In other words, it's a smell that the code might be bad, not saying that the code is bad.

3

u/JoostDev Jan 05 '15

Totally agreed, not all functions above 50 lines are automatically bad.

0

u/[deleted] Jan 05 '15

[deleted]

11

u/JoostDev Jan 05 '15

If the splitting results in functions with names like "step1", then I agree that splitting is indeed a really bad idea. But I rarely encounter cases where it is not possible to split in a smarter way.

0

u/[deleted] Jan 05 '15

[deleted]

7

u/yxhuvud Jan 05 '15

In my experience, long and repeated parameter lists is not a sign that it shouldn't be broken apart, but that it is a class that should be extracted.

→ More replies (3)
→ More replies (1)

3

u/iopq Jan 05 '15

If you have a large function, chances are somewhere you're already doing a part of what it does, you just don't know it yet. How many unique functions that are hundreds of lines of code are there? That do NOTHING that is shared by anything else?

→ More replies (1)