Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Good code should not only be "readable", but it should be as easy to read as possible. Potentially a lot of people will read this code, and all of them will need to spend extra-time processing it because it's hard to read. Long lines are usually harder to read, which is why most coding guidelines recommend limiting lines length to 80 chars, this one is 178.


If you pick bash as your programming language, don't you already throw "readable" out of the window?

Perl gets a lot of flak for being unreadable, but I personally have more difficulty understanding bash code than perl (not implying that perl is super readable).


Lets say you write in bash like this:

  if [[ $OPTION =~ = ]]
  then
      declare "BOCKER_${OPTION/=*/}=${OPTION/*=/}"
  else
      declare "BOCKER_${OPTION}=x"
  fi
Going from here, if you rewrite this in golang you'd probably improve readability.

But the readability has not been "thrown out of the window" yet, like in this case:

  [[ $OPTION =~ = ]] && declare "BOCKER_${OPTION/=*/}=${OPTION/*=/}" || declare "BOCKER_${OPTION}=x"


Oh I see your point.

Yeah, that was unnecessary. Ironically now I remember that I was once frustrated by someone who was using Boolean logic to emulate if/else in Python.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: