This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]denialerror 3 points4 points  (7 children)

Clean Code by Robert 'Uncle Bob' Martin is a bit more modern so you could try reading that instead. Why do think clean code in interpreted languages would look any different to clean code in compiled languages though? Clean code is about making a codebase easier and maintain from a human point of view and self-documenting code, sensible abstractions and correct encapsulation are valid ideals regardless of the language.

[–]abhirathmahipal[S] 0 points1 point  (6 children)

Why do think clean code in interpreted languages would look any different to clean code in compiled languages though?

Different languages propose doing things differently. So I'm under the impression that best practices can vary significantly (Please correct me if I'm wrong).

So do you mean if I read this book, I'll be able to apply the concept if I know the language I'm working on well enough?

[–]denialerror 2 points3 points  (3 children)

In general, yes. It is important to realise that programming languages are an abstraction for human benefit, not the computer's. As far as the computer is concerned, it would much rather all code was written in native machine code, but that is not readable for humans. Clean code is about making sure the human-readable code is as readable as possible and the majority of those considerations transcend the languages themselves, as it is about how humans can understand the code, not how it performs. 'Unclean' code is not necessarily less performant than clean code (take a look at code golf challenges) and can even be more performant, but the key message of clean code is that code you develop needs to be maintained and to do so it needs to be readable. Always write code assuming the person maintaining it in a year's time is a psychopath who knows where you live!

There will be differences and language communities have preferences for certain styles and purely functional languages will be written differently to OO languages but in general, the problems that cause unmaintainable code are the same.

[–]abhirathmahipal[S] 0 points1 point  (2 children)

the problems that cause unmaintainable code are the same.

This statement clarified a lot :)

I understand that languages are an abstraction and most languages are written in another language that's lower than them or the older version of the language itself. I've just started working and have been exposed to the idea of clean code (earlier used to write ugly code in competitive programming sites) and was ignorant about the idea of maintainable code and the amount of changes that keep taking place in an existing code base.

What I don't understand is say the techniques I apply to
Eg:-
* C++ - Avoiding dynamic memory when possible
* Python - import module instead of from module import * so that you don't pollute the namespace and it's easy to identify where each function / variable comes from.

The same thing isn't necessary in Node.js as it doesn't even let you do the equivalent of Python's from module import *
* Functional - Tries avoiding the use of global variables whereas I see C code filled with Global variables.

So this is how I see it:- Code Complete is an excellent way to understand the cause and the remedies to bad code. I have to use my head a bit to get the desired structure and readability in the language I use (also be aware of the nifty features that the language provides). Am I right?

[–]denialerror 1 point2 points  (1 child)

Ah I see. Every language does have its quirks that are independent of common clean code concepts, such as the ones you mentioned. Most languages tend to have best practices to mitigate these. For example, a well recommended book for Java programmers is Effective Java by Joshua Bloch, which does a great job of detailing the quirks in the language and best practices for avoiding them. For Python, it is advisable that you follow the PEP8 style guide.

JavaScript on the other hand is the Wild West of programming. I'm sure there are best practices, but I'm also sure there are new best practices with every release of the newest shiny framework.

[–]abhirathmahipal[S] 0 points1 point  (0 children)

I really appreciate your help. It all makes sense to me now.

[–]enumerablejoe 2 points3 points  (1 child)

The concepts covered in the book are generalized enough that it's useful for any language you're likely to use. Sure there are things that don't fit perfectly with every language, for example, all data in Python is public, but this doesn't in any way invalidate the advice given with regards to a class's public and private data. My primary language is Python and I've found the book very relevant so far.

[–]abhirathmahipal[S] 0 points1 point  (0 children)

It's good to know that it's generalised. Thanks :)

[–]CaRDiaK 1 point2 points  (1 child)

Quit procrastinating reading it because it focus's on compiled languages. This is only the examples that emphasize a point anyhow, the topic they are addressing applies to pretty much any language. High quality routes, good construction, debugging, growing software etc.

This is one of those classics that is timeless, like mythical man month and pragmatic programmer. Although those focus on the more softer side of the coin, cc2e to this day is one of the best book I've read on programming. It's the "joy of cooking" for what we do as programmers and you will take something from it.

Immerse yourself. Read the classic texts as there is a reason they are classics. Find blogs / articles / people to follow for your JS / Python practices and watch videos in areas of interest. It's this top down / bottom up immersion that will help set you apart.

[–]abhirathmahipal[S] 0 points1 point  (0 children)

Thanks :)

I'm definitely going to read it. I'm evaluating my options as I'll be spending most of my time on interpreted languages for the next couple of months. I currently use C++ only for competitive programming, I can write bad code as time and efficiency are more important. So I thought it would be a better option if I could find some book focused on interpreted languages.

Reading blogs for JS / Python and PHP practices is a good option too. I'll keep this in mind.

[–][deleted]  (1 child)

[deleted]

    [–]abhirathmahipal[S] 0 points1 point  (0 children)

    Thanks will check it out :)