Live data from Hacker News

Signs You're a Crappy Programmer (and don't know it)

damienkatz.net

61–66 of 66 posts

Re: Signs You're a Crappy Programmer (and don't know it)

#61
post #59

Earlier quoted context omitted.

I've seen whole projects fail over that discussion. Maybe it really should be used as an interview question. There is no point in mixing same-liners and new-liners together. Only remedy might be to use a programming language without curly braces.

I have to admit it's a pet peeve for me -- even more than choice of languages, oddly enough. When scanning code, I just like the ability to see my control blocks clearly. Simply because you can do something like this if (a==b) { doStuff(); } else doOtherStuff(); Doesn't mean you should. I would consider this a little bit of a hangup on my part, though, as it seems other programmers go the other way. An interesting to…

I would not put everything on the same line, but I admit to putting the opening bracket on the same line. In fact, I consider the other variant extremely ugly. Just consider

  if(...)
  {
    ...
  }
  else
  {
  ... 
  }
vs

  if(...) {
    ...
  } else {
    ...
  }
I can't for the life of me understand why someone would want to move the bracket to the new line ;-) It's just empty (wasted) space without any meaning. I can see the control blocks with the tighter version just fine, plus, it's the Sun Coding Convention for Java. But it's really a fruitless discussion...

Re: Signs You're a Crappy Programmer (and don't know it)

#62
post #52

Earlier quoted context omitted.

One very useful idiom: while(readLine()) { process lines... } where readLine() encapsulates the repetition and returns eof as well.

where is the line (to be processed) stored?

In my comment I assumed it's a line in a file and that the termination condition is eof, but you can generalize to any aggregate of items. I'm just combining the test with the increment step so we can use a simple while loop without having to peel the 'first increment' step out of the loop. If that makes any sense :)

Re: Signs You're a Crappy Programmer (and don't know it)

#63
You know that you are a lousy programmer (and also lousy at doing other things) if you start to make rules although smart people know:

- rules are for people who cannot think

- every rule has a context where it fits perfectly, but

- every rule has many contexts where it doesn't fit at all

Rules only reflect your current knowledge and your current working situation. This is subject to change.

Re: Signs You're a Crappy Programmer (and don't know it)

#64
post #52

Earlier quoted context omitted.

where is the line (to be processed) stored?

In my comment I assumed it's a line in a file and that the termination condition is eof, but you can generalize to any aggregate of items. I'm just combining the test with the increment step so we can use a simple while loop without having to peel the 'first increment' step out of the loop. If that makes any sense :)

Thanks.

I was trying to point out that the idiom becomes while(line=readline()) which I'd rather avoid since = and == often get confused in a conditional.

It would normally be silly to get into this level of detail but I use this so often.

Re: Signs You're a Crappy Programmer (and don't know it)

#65
post #64

Earlier quoted context omitted.

In my comment I assumed it's a line in a file and that the termination condition is eof, but you can generalize to any aggregate of items. I'm just combining the test with the increment step so we can use a simple while loop without having to peel the 'first increment' step out of the loop. If that makes any sense :)

Thanks. I was trying to point out that the idiom becomes while(line=readline()) which I'd rather avoid since = and == often get confused in a conditional. It would normally be silly to get into this level of detail but I use this so often.

Oh, good point. I am tolerant of globals :). Also of assignment instead of equality in conditionals (with an extra layer of parens to flag their unconventional nature). I've also used class methods where the implicit variable is in this.

Re: Signs You're a Crappy Programmer (and don't know it)

#66
post #61

Earlier quoted context omitted.

I have to admit it's a pet peeve for me -- even more than choice of languages, oddly enough. When scanning code, I just like the ability to see my control blocks clearly. Simply because you can do something like this if (a==b) { doStuff(); } else doOtherStuff(); Doesn't mean you should. I would consider this a little bit of a hangup on my part, though, as it seems other programmers go the other way. An interesting to…

I would not put everything on the same line, but I admit to putting the opening bracket on the same line. In fact, I consider the other variant extremely ugly. Just consider if(...) { ... } else { ... } vs if(...) { ... } else { ... } I can't for the life of me understand why someone would want to move the bracket to the new line ;-) It's just empty (wasted) space without any meaning. I can see the control blocks wit…

I on the other hand find this quite elegant

(...) ? $doThis : $doThat;

Post reply on HN