Skip to main content

Posts

Showing posts from May, 2020

Intuitive Programming - Fragile Constructors

There is nothing that says that a constructor of a class can’t perform complex transactions, but most of the people do not expect them to be long running or fragile.  When someone is writing a constructor that connects to a database, makes a network call, parses files on disk or something that can error out, that is not intuitive.  In the words of Big Lebowski “you are not wrong, you are just an a-hole”



My overall mantra of intuitive programming and design is that you should create systems with the principle of least surprise to the caller and maintainer.  Most of the programmers assume that object constructors rarely fail and rarely take a long time.

Constructors are generally used to create object and assign default or provided values to the fields in the object.  The trouble with overloading the constructor with something super heavy is that while you can remember that this is a “special constructor” others won’t intuitively get that.  Often times when you do something strange you…

Intuitive Programming - to Class or not to Class

Reading code is only easy in trivial systems and a system that has a lot of functionality usually has a lot of code.  Reading code is a critical part of what software developers do every day so it makes sense to make reading code easier by making the code more intuitive to the largest population of programmers.

There are books and numerous articles on software design, patterns and naming conventions.  I encourage everyone to read those, this blog post is not an attempt to create and exhaustive guide to writing good code.  Here I am going to cover a few small hacks that help people understand what your are doing faster.  The first topic of discussion is classes.

When I started programming in 1990s Object Oriented Programming (OOP) was all the rage.  After 25 years I have noticed that software field has fashionable trends where “everything must be so”, so in 1990s a lot of people were into C++ and Java (today the fashionable thing is micro services). Objects and classes were not invent…