Over a million developers have joined DZone.

Most of the Code I Wrote >6 Months Ago Sucks

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

The thing about learning a new programming language is that it is a humbling experience. You may have been an expert in another language after years of honing intricate knowledge of its behaviors and foibles. Yet when learning a new language, it counts for very little - at best you’ll have an experience to help you accelerate your learning of the new language, at worst it will be a chain and ball of bad habits holding you back in old, bad habits.

After 2-3 years of using Scala, I’d like to think I am approaching the level of becoming a competent Scala developer (though Dunning-Kruger is always a risk), but I know that there is undoubtedly a lot of depth that I have yet even scratched the surface of. I find myself taking spurts if improvement once about every 2-3 months, and find myself cringing at some of the code I wrote further back than that. Code that is older than 6 months I positively want to disown and deny any knowledge of (though it might be hard, as much of it is open source).

Going from an imperative style to more functional style, I’ve noticed the following changes in my own code over the last 6-9 months:

  • Code I thought was fairly “functional” 6 months ago in fact has a lot of very obvious imperative “smells” seen with my eyes today.
  • Though I knew mutability was bad, 9 months ago I still “cheated” occasionally as my mind had not yet shifted fully to solve all problems immutably.
  • I define fewer vals (and no vars) these days, preferring more concise composition of functions.
  • These days I find functions that return “Unit” smelly: returning Unit to me implies that a function is probably side-effecting.
  • A lot of code now boils down to simply manipulating Lists and Options with filter, folds, maps and flatMaps (see point 3. And maybe LISP got it right in the naming of the language).
  • 6 months ago I really didn’t get implicits. At all. Now I feel I’m starting to have a decent appreciations of where they fit and where they don’t.

These are a few of the things I have noticed in the evolution of my Scala code. I’m sure looking back in another 6 months, I will find a lot of bad smells in code I write today: I would be slightly concerned if that wasn’t the case, as it would imply I haven’t been learning enough.

To ensure I think my Scala code from today “stinks” in six months time, I will try to integrate more perspectives into my toolbox: though I’m unlikely to use any of them for production code, I will try to improve my Clojure skills, and perhaps learn me some Haskell, you know, for great good. Even if you only use a few of your tools, awareness of a wide variety of tools in your toolbox can only improve you as a programmer.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Published at DZone with permission of Wille Faler, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}