Good or bad code


  1. Introduction
  2. Test
    1. Application structure
    2. Code style
    3. Database access
    4. Quality approach
    5. Process
    6. Result


We all know that there is good code and bad code.

We also know that a lot of bad code is written every day.

The following little test is a combination of a joke and some very serious points about bad code.

Note that the rules apply to all languages. It is not just the languages known for well structured programs like Pascal, C++, Java, C# etc.. It is also for languages with a tradition for a more relaxed attitude and lots of developers with no formal education in software development like VB, PHP etc..

The test questions are for server side part of web applications. That is probably where most bad code is seen. You will need to sligtly interpret questions for different types of applications.

There may be questions where you are not fully in one or another answer, but you can try both answers and see how you score with each.

And yes the bar is set rather high. :-)


Application structure:

Question: how are different aspects of the application separated?

They are not separated - I mix database access, calculations and HTML output freely
I have separate functions for HTML output, calculations and databaase access
I have separate source files for HTML output, calculations and databaase access
I have a formal layer model with presentation, business logic and database accesss and each layer has separate source files

Question: do you use any frameworks/libraries?

Yes - my own
Yes - a few well known
Yes - several well known

Code style

Question: how long are your functions/subroutines/methods?

I don't use functions/subroutines/methods
Average 101+ lines of code
Average 21-100 lines of code
Average 0-20 lines of code

Question: do you use global variables instead of passing everything as arguments to functions/subroutines/methods?

I don't use functions/subroutines/methods
A few places

Database access

Question: do you use prepared statement/parameters?

For some SQL statements
For every SQL statement

Question: what would it take to change from one database to another (like from MySQL to SQLServer)?

All database calls would need to be changed + most SQL/xQL statements would need to be changed
Most SQL/xQL statement would need to be changed, but database calls can be kept as is
All database calls would need to be changed, but SQL/xQL statements can be kept as is
Just need to change configuration

Quality approach

Question: how do you handle errors/exceptions?

I just code each piece to make them work
I am careful about testing return values and catching exceptions and abort and display error message if something goes wrong
I handle everything and I have my own little framework for giving users a general error message in production mode and provide lots of debug info in development mode
I use exceptions for exception handling and I use a well known logging framework to log everything I need to troubleshoot issues

Question: do you use unit testing?

Yes - I have my own handcoded tests to test the core functionality
Yes - I use a well known unit test framework and I test the core functionality
Yes - I use a well known unit test framework and I aim at high test coverage


Question: how do you design your application?

I don't - I just start coding
I put down some core ideas on paper to make sure I can come through before I start coding
I create a formal document with digrams and text before I start coding

Question: how is your approach to performance?

I just make the code work
I fine tune every line of code to make it be as fast as possible
I try and write nice clean code and if I feel it is too slow I usually know where to optimize
I write the code strictly for readability, then I measure performance of each part and in case a part has a performance problem I optimize that (but keep the original code as a comment)


You scored:


Article history:

Version Date Description
1.0 September 2nd 2016 Initial version
1.1 October 8th 2016 Add content overview

Other articles:

See list of all articles here


Please send comments to Arne Vajhøj