Laran Evans
I develop software people love to use.
  • Home
  • About
  • Contact
  • Resume
  • Testimonials
Skip to content
  • Entrepreneurship
    • Leadership
    • Project Management
    • Team Development
    • Time Management
  • Puzzles
  • Software Architecture
    • Cloud Computing
  • Software Development
    • Algorithms
    • CSS
    • Java
    • Javascript
    • MySQL
    • PHP
    • Python
    • Ruby and Rails
    • System Administration
« Writing Code That Isn’t Clever
100 Bright Ideas »

The Value of Code Clarity

By laran | Published: 2007/09/04

Programming is a “read-mostly” endeavor. Source code should easy to read. Source code should emphasize code that “does stuff”, not “busy work” code or “code noise”.

Get/setters are “busy work”. They’re frequently over-used for the sake of adherence to the Java beans convention.

I recently spoke with Andrew Myers, a Cornell professor whos specialty is programming languages (among other things). I spoke with him about writing a small bit of syntactic sugar for Java to allow getters and setters to be generated automatically at compile time for class attributes for which no getter or setter existed. His response was insightful.

I typically need getters and setters to access private class attributes. Professor Myers basically told me that it sounded like I wasn’t properly designing my classes. Instead of declaring private attributes and allowing access to these attributes via get/set methods, I should be just declaring the attributes with the appropriate scope. This seems like a perfectly obvious answer. So why didn’t I do that in the first place?

I use the Spring Framework a lot. Spring provides aspect-enabled dependency injection. This is a great facility to have. It allows for code that can be simply reconfigured via xml descriptors. The alternative would be to require that the code itself be modified and recompiled to produce a new executable. Overall this isn’t a very flexible option. So Spring provides a great deal of value in this regard.

The downside to the way Spring does dependency injection is that it requires public setter methods for each attribute that can be injected. This is an easy enough thing to do. But, it encourages a very sloppy paradigm of having setters in order to provide the hook that Spring needs.

For Java, Spring does a good job. The Java language, being compiled and statically typed just requires more verbosity than a language like Ruby.

I personally find the Ruby syntax for declaring class attributes to be much less verbose and much more clear.

This entry was posted in Software Development. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
« Writing Code That Isn’t Clever
100 Bright Ideas »

Post a Comment

Click here to cancel reply.

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • About Me

    I've got a masters degree in computer science and over 10 years of experience building web-based systems using Java/J2EE, Ruby, Rails and PHP. I'm a strong believer in the effectiveness of Agile Methods. Read more »

  • Subscribe

  • Similar Posts
    • Writing Code That Isn't Clever
    • Top Ten Developer No-Nos
    • Why Frameworks Die
    • 36 Minutes to Get Back On Track
    • A Few Points on Writing High-Performance Software
  • From Around the Web

    • Web App Business Models: User Needs and What People Pay For (Box UK Blog)
    • Blog Writing Tips from the World’s Most Famous Authors (Blogsessive.com)
    • How to get exponential success on your blog (CatsWhoBlog.com)
    • The Four Stages of Growing a Blog (Daily Blog Tips)
    • Insert Google Analytics without editing your theme (WpRecipes.com)
    Shared Items
  • Recent Posts

    • 80 pages of Ruby on Rails Performance Optimization Tips
    • Ruby Garbage Collection In-Depth
    • Binary Logic Basics
    • Kuali in Nacubo Magazine
    • Ruby Blocks, Procs, Lambda
  • Older Posts By Month

    Let's Talk

    Ask a question below. You'll be prompted for your name and email after you click the "Ask" button.

Know more. Accomplish more. Succeed.