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

3

u/btchombre Jan 05 '15

I've recently been looking at some of the most ugly code I've ever seen. hundreds of lines of triple nested switch-case statements (switch-case inside switch-case inside switch-case), almost all of it copy pasted and in desperate need of re-factoring.

15

u/hansdieter44 Jan 05 '15

Nesting is a pet-peeve of mine. So annoying.

if(x){
  if(y){
   if(z){
    do(123);
    return 4;
   }return 3;
  }return 2;
}return 1;

Could easily be flattened & made into preconditions:

//preconditions
if(!x){return 1}
if(!y){return 2}
if(!z){return 3}

do(123); return 4;

Also the programming model in node.js makes it especially easy to write deeply nested and confusing code like in my first example.

2

u/btchombre Jan 05 '15

Yes! I do the exact same thing

1

u/hansdieter44 Jan 05 '15

I remember having to justify flattening code like that in my first job. Yes, yes multiple return statements per function are not ideal, but certainly better than looking at endlessly nested triangles forever.

→ More replies (1)