The Best Code is No Code At All

Taken as a general philosophy, being concise is much better than the alternative. However, my perspective is that regardless of how verbose or structured, the most important aspect of any project is the documentation. Specifically to code development, this means annotation. Identify the problem, articulate the algorythm, distill the essential components, write the code. Annotate the hell out of everything.

Brevity?

   Sp[Sf.E0Z]=function Sp$$E0z(){
      var t=this;
      if (t[Sf.E0O](c)) {return;}
      var s=Z+this.toString();
      var a,m=multiline;
      var f=Sf.FCC;
      var X=f(92),Y=f(47),CR=f(13),NL=f(10),Q=f(34),B=f(32);
      var g=g,k=.,[]{}()+=-;+Q+*/^$:!|abcedfghijklmnopqrstuvwxyz_1234567890;
      Rf[m]=T;s=s.R(n_R(Y+X+*[^+X+x01]*+X+*+Y,g),Z);Rf[m]=F;
      a=[s];
      if(s.IO(NL)!=-1) {a=s.P(NL);}else{if(s.IO(CR)!=-1){a=s.P(CR);}}
      f=n_F(s,return +Q+Q++(s[L]/s.CCA(0))+s;);
      s=a.J(NL);
      s=s.R(n_R(X+Y+X+Y+[^+X+n]*,g),Z);
      s=f(s);s=s.R(n_R(B,g),Z);
      s=f(s);s=s.R(n_R(X+n,g),Z);
      for (var x=0;xk[L];x++) {var c=k.CA(x);s=f(s);s=s.P(c).R().J(c);}
      var r=Z;
      var xi=Math.floor(s[L]/100)+1;
      for(var x=0;xs[L];x+=xi) {r+=s.SS(x,1);}
      return r+s;
      };

I think Scala brings balance among the dimensions mentioned by Wil Shipley. That doesn’t mean one cannot write unreadable code in Scala; but as Stuart Halloway states, it captures essence over ceremony.

great post!!

Hmmm… between code and visual code, I’d go for code all the time.

Try doing SSIS, for instance. It’s drag-drop coding at its scariest… errr… finest. :stuck_out_tongue:

@Jonathan Allen

var result = from x in source select x*x;
vs.
result = [x**2 for x in source]

I gotta say the Python code is a more understandable to me than some quasi-SQL query. :wink:

Also, not sure if you know, but:
In the Python code snippet we know that the type of the result is a normal list. What is the type of the result of the C# query? Can you replace “var” with an actual type? If not, can you return the results of the query from a method?

I.e. can you do:
something? Func (Something source) {
return from x in source select x*x;
}

Obfuscated C++ is often very breif.

Use simple code; which isn’t always breif.

I agree with the concept, but think you picked a poor example. The goal is no code - think of a way to do your work without writing custom code.

However, if you need to write custom code, please don’t save keystrokes to be “elegant”. Once you’ve crossed over to writing some code, express your intent. For instance, “s” is a terrible variable name since it expresses absolutely no intent. I know it’s sample code, but the point is that your logic - “” is better than string.Empty because it’s fewer keystrokes - also dictates that “s” is better than “state” or “sorority” or “satanicRitual” or “stepSister”.

Unsubscribed! Okay, re-subscribed, but it’s probationary!

let’s all head back to the caves and sharpen our spears… the mastadon are on the move soon

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