Wednesday, 11 September 2013

Legibility Wins and Losses (Part 1 in an Occasional Series)

I keep banging on about Scala’s syntax and the resulting legibility.  I’ve also mentioned more than once that I think the style propounded in Atomic Scala is the clearest I’ve read anywhere, and is likely to be a deciding factor in the books longevity.

What follows is a round-up of the wins, and losses, for legibility, that I’ve encountered so far.  this is all opinion, so please feel free to ignore everything in this post.

Wins

  • Scripts and classes
  • No semi-colons
  • vals and vars (as well as immutability as a general concept)
  • type inference
  • function definitions
  • The for loop (and how they play with Range literals)
  • Class Arguments
  • Named arguments
  • Default arguments
  • Case Classes (because of the terse syntax – no need for a body!, the removal of the need for “new” and the free “toString”)
  • Some of the methods in core classes (e.g. ‘to’ and ‘until’ when creating Ranges)
  • Overloading
  • String Interpolation
  • Optional Parameterized Types (square brackets just seem more apt for a DSL, but being optional means I can avoid using them unless its necessary)

Losses

  • :: (aka “prepend to a List”)
  • Some of the methods in the Collections classes (e.g. Vector.sorted)
  • Constructors (where did they go? they’ve just become a “run” of the body of a class. And yes, I know about the “Constructors” Atom in Atomic Scala)
  • Auxiliary Constructors
  • Function definitions within function definitions
  • “”””bleh””” (triple quotes; really?)

Undecided

  • Pattern matchers
  • The Scala Style Guide
  • Optional parentheses
  • Optional ‘.’ when calling methods on objects
  • Return type inferral

Could I have a style guide which just banned the “Losses” way of doing things?  Yes. We do that in Java all the time.  Might I be wrong about some of these?  Yes.  Noob’s prerogative.  Would an IDE help? Yes, syntax highlighting is a boon in my opinion.  Have they chipped away at my enthusiasm?  Not really.  The more I see, the easier it becomes to read.  It’s generally getting less and less outlandish looking with every passing day.

No comments:

Post a Comment