Hackernoon logoWe Should Get Rid of "Hello, World!" ForeveršŸ’© by@mcsee

We Should Get Rid of "Hello, World!" ForeveršŸ’©

Author profile picture

@mcseeMaximiliano Contieri

I’m senior software engineer specialized in declarative designs and S.O.L.I.D. and Agile lover.

Every tutorial I've read for the last 30 years starts with the infamous 'Hello World' example. This could be one of the reasons we write crappy software.

"Hello World" is theĀ first programĀ we make in every language.

We can measure the complexity of language by counting the lines it takes to produce the desired output.

We can also time how much does it take to aĀ newbieĀ to figure out the solution (this is also known asĀ "Time to hello world" (TTHW)).

These two metrics are uncorrelated to productivity.

Many sites compile differentĀ Hello WorldĀ programs in a lot of languages.

Helloworldcollection

The Problems

TheĀ Hello WordĀ example has a lot of problems introduced early when developers are making their first steps in programming.

  1. It usesĀ globalsĀ in many languages. Global functions are a code smell. Teaching them to newcomers in theirs first example is conflicting.
  2. Hello WorldĀ yieldsĀ side effectsĀ (on the console, file system, printers, etc.).
  3. We write the code, and we cannot test if it is working. We can manually check for the output, but our software cannot assert it our outcome was right.
  4. If ourĀ HelloWorldĀ works today we cannot ensure it will keep working tomorrow.

Code Smell 17 - Global Functions

The Solution

All developers should start with:

function testFalse()
{
    Assert(1==2)
}

Advantages

  1. We start with a broken test. This is the first step to start developing software according toĀ test driven developmentĀ technique.
  2. We introduce developers to aĀ Continuous Integration/Continuous DevelopmentĀ pipeline with their very first instruction.
  3. We use noĀ GlobalsĀ or side effects.
  4. We show the importance of early testing.
  5. We stress how important is to have working code andĀ automated testsĀ from the very first second.

How to Squeeze Test Driven Development on Legacy Systems

Conclusion

We need to stop writingĀ HelloWorldĀ as the first sentence of a language.

Next time you come across a new fancy language, please start with a broken test.

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.