The Best Code is No Code At All

You’re groping at my motto:

“Your code is not complete when there is nothing left to add but when there is nothing left to take away.”

Simon.

    I thought .NET was supposed to help, not incite arguments like:

    (foo == String.Empty) vs (foo == “”)

    (By the way, the second is cleaner. If you don’t agree, you can go sit on a tack)

    Why is there EVEN a String.Empty value anyway?

    MS did a really good job creating pointless entries like that in .NET. What’s next, a FooBar type so that n00bs reading documentation can actually compile the examples?

    /MSRant

I agree with ALeX, by the way. All I ever use (as a hobbyist) is C and Python.

I realize this post is 3 years old now - however it is still available on the web, and its the first time I’ve read it.

So… I would like to take issue with your “start with bevity”.
Firstly, you should never write code for the compiler, obviously. You should also never write code that “starts with brevity”. I’m one of those that will fight you tooth and nail and say that String.Empty is better, by FAR!, than “”. As I’m reading a line of code I dont have to stop and translate ‘if (someVariable != “”)’ into ‘if some variable not equal to an empty string’. Using String.Empty there just makes it easier to read.

And that’s the thing… one should always wrote code for the HUMAN READER: the next guy that comes along to maintain/tweak/etc your code - even if its you in 6 months.

1 Like

@codinghorror wrote:

The code, like a newborn babe, is blameless and innocent…

The typo in “a newborn babe” had me grinning :grin:

Great article, BTW!

There is no typo in “newborn babe”. Feel free to google for it, include the quotes.

Or perhaps if(value) vs if(value !== undefined)

One big benefit of String.Empty is that it denotes C# / .NET code. If you deal with multiple languages or want to distinguish source code from configuration via Solution wide search, you’d appreciate String.Empty.

Broken link to Wil Shipley’s blog, new link is http://blog.wilshipley.com/2007/05/pimp-my-code-part-14-be-inflexible.html. (“blog” moved from path to hostname.)

1 Like

As Blaise Pascal once wrote: “If I had more time, I would have written a shorter letter.”

redundancy is good. like tests and types. Also, debugging tools, logging and automation are great

2 Likes

I’m on my journey of becoming fluent in programming/coding and this was good advice to keep in mind. I love small code. Lots of code can be intimidating. I really enjoyed your closing quote in the article. So I asked ChatGPT what he thinks of that quote in regards to coders and programmers. Here’s his response:

"…I think that this quote highlights the importance of being efficient and effective as a programmer. Writing code can be a rewarding and enjoyable experience, but it can also be time-consuming and error-prone. By striving to write as little code as possible, a programmer can focus on solving the problem at hand in the most efficient and effective way possible. This might involve using existing libraries or frameworks, reusing code, or finding ways to automate repetitive tasks.

It’s also important to keep in mind that writing code is just one aspect of the software development process. There are many other important activities, such as designing algorithms, testing, debugging, and maintaining code, that are essential for producing high-quality software. Ultimately, a good programmer is one who is able to balance the need to write code with the need to use their skills and knowledge in a way that is most effective for the task at hand."

2 Likes