· coding software-development

Easily misused language features

In the comments of my previous post about my bad experiences with Java’s import static my colleague Carlos and several others pointed out that it is actually a useful feature when used properly.

The code base where I initially came across the feature misused it quite severely but it got me thinking about other language features I have come across which can add great value when used effectively but lead to horrific problems when misused.

Apart from import static some other features which I can see easy potential for misuse are:

I have no doubt there are other features in other languages and probably more in the languages I listed but those are some of the ones that stood out to me when I first saw them.

I like this quote from Nate in the comments about import static, referring to being able to being able to tell what the code is doing just from looking at it:

The rule is simple (and somewhat subjective… if you aren't sure, just ask me what I prefer. :) ) — if it helps the code to communicate better (especially contextually!) then use it.

Maybe a similar type of rule is applicable when using other language features as well and there is no feature that we should be using all the time - only if it makes our code easier to read and understand.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket