• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What Are the Hallmarks of Good / Bad Code?

Page 4 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
do not use underscores in variable names ... that is bad code!

(semi serious about this too, i can't stand it - camel case ftw!)

i am a java programmer, but i honestly find underscores to be more readable

i dont do it in production code, but use it in test case method names

what is more understandable?

1. public void calculatePremiumReturnsCorrectFactorCoefficients()

2. public void calculatePremium_returns_correct_factor_coefficients()

i vote for #2
 
i am a java programmer, but i honestly find underscores to be more readable

i dont do it in production code, but use it in test case method names

what is more understandable?

1. public void calculatePremiumReturnsCorrectFactorCoefficients()

2. public void calculatePremium_returns_correct_factor_coefficients()

i vote for #2

I prefer #1 myself. I used to use #2 but I have since changed my tastes I guess. At work we use StyleCop to enforce variable naming conventions so the code is consistent, which is probably more important than #1 or #2. I imagine there is a similar plugin for the more common IDEs that support Java but I have never looked.
 
Which version are you using? I'm using 2013 Express. If I type this:
Code:
if (condition) {
and hit enter, it automatically turns into this:
Code:
if (condition)
{
All of the settings are on default.

As much as I understand your qualms with this, I understand why the later is preferable. When you're editing code, it is advantageous to have your brackets as far to the left so when you ctrl-[] , you don't have to press the end key to get to the starting bracket.

However, as I edit and mimic other peoples code, it doesn't slow me down much.

Some other keys everyone should be using.

ctrl-ml and ctrl-mm

Try it. You'll like it,
 
Last edited:
i am a java programmer, but i honestly find underscores to be more readable

i dont do it in production code, but use it in test case method names

what is more understandable?

1. public void calculatePremiumReturnsCorrectFactorCoefficients()

2. public void calculatePremium_returns_correct_factor_coefficients()

i vote for #2

#1 is easier on the eyes for sure, also easier to type.
 
Hello,

I'm new to computers, and at this point my metric for what constitutes good programming is functionality. That is, if a piece of code simply does what it's supposed to, in my eyes it's good.

However, I'm aware enough to understand that even though code may be functional, it may still be poorly constructed.

So, experienced programmers, how do you know when looking at source code whether or not the writer knew what he was doing?

What are the hallmarks of good programming? What are the hallmarks of bad programming?

Can you recommend certain coding styles to emulate? Can you admonish me from emulating others?

Thanks.

Bad code == spaghetti or over-engineered, equally frustrating to deal with.
Good code == KISS and documented in code if you are doing something you have to think twice about.
 
i am a java programmer, but i honestly find underscores to be more readable

i dont do it in production code, but use it in test case method names

what is more understandable?

1. public void calculatePremiumReturnsCorrectFactorCoefficients()

2. public void calculatePremium_returns_correct_factor_coefficients()

i vote for #2

I am on #3 .. at this level I dont give a flying .. they're equally acceptable to me.
 
I am going to print this out and put it up at work. LOL!

lol yeah i just heard it at codemash and laughed for a good minute when the guy said it. i think he might have said it better though, maybe something like:

"code is like a joke - if you have to explain it, it's not very good".
 
There are contexts in which all-caps is not only unobjectionable, but increases comprehension. Specifically, case-insensitive languages like SQL. The reason that the upper-case convention was adopted for SQL keywords early on is simply that when the language is not case-sensitive you end up with everyone using their own personal approach, i.e. select, Select, and SELECT.

True, there are contexts in which all caps can aid in comprehension, such as in street signs...advertisements, examples that Ken gave - but him implying that carries over to every other aspect of typography is not true, especially not in most coding environments.

But as you point out, certain case insensitive languages such as SQL prefer keywords in all uppercase, and guess what? The designers of the code editor of SQL Management Studio went ahead and added a lot of spacing on uppercase key words. It's anticipated, and that's what makes it easy to read.

Below is a comparison of the DECLARE keyword typed out at 100% zoom, all fonts default in Visual Studio 2013 vs SQL Management Studio 2008

pic.png


I'm not sure how anyone can defend Ken's claims that all uppercase is always easier to read and shouldn't ever bother anyone because of street signs and the such - that's a gross oversimplification.

There *is* something wrong in using all caps when not convention, you're just making it tougher for everyone else if you don't see why.
 
Last edited:
Which version are you using? I'm using 2013 Express. If I type this:
Code:
if (condition) {
and hit enter, it automatically turns into this:
Code:
if (condition)
{
All of the settings are on default.

I have Visual Studio Express, whatever the latest version is before it went completely free with the open source announcement.

I can understand them "forcing" the second option, as it is easier for readability if you're used to the former. While, I believe the { is implied, there are plenty of times I've not used them at all. Forcing it on the line below, notifies me immediately there is more encapsulated for this statement than a single line.


And for those arguing that having serifs on I's and 1's makes it harder to read all caps, you need to get your eyes checked and update your glasses. It isn't.
 
Back
Top