DEV Community

joshdrichest
joshdrichest

Posted on

Need Help With An Example of Clean, Elegant code VS Bad, Messy Code

Evening everyone,

I currently teach a programming class and am teaching them from Scratch, my current batch of students are all exceptionally clever but end up doing a huge massive chunk of code for something that could really only take a handful of lines of code.

When I sat with them and talked about how you should think about how clean, elegant code is far more impressive than huge chunks of code that’s all over the place - it seemed to fall on deaf ears. I think they’re currently thinking the more code they have on the screen the more epic their program is.

What I wanted to bring them in their next class is an example of code (hopefully for the same problem) showing a really messy and bad piece of code, and also the clean, elegant solution to show the point I am trying to make.

Does any one have any examples they could point me in the direction of? It can be a really basic problem and solution, I just want to show how say, sure you could write 200 lines of code to do one thing, but a bit of thought could lead to say 25-50 lines doing the same thing, far more efficiently and cleaner.

Thanks in advance!

Top comments (0)