IronWing
No Lifer
- Jul 20, 2001
- 72,997
- 34,210
- 136
A much better way would be to give your variables good names.Good (possibly, depending on context): a=x // Store the x-position in the accumulator.
A much better way would be to give your variables good names.
int accumulator;
int x-position;
accumulater = x-position;
Now you don't need to comment that line. And it is suddenly more readable than any comment could possibly be.
For some reason, a majority of programmers thinks that they need to choose the shortest variable-name they can come up with. Wrong. Pick descriptive names. 20+ characters long if you have to. Do this for variables, functions, constants, everything.
Don't like it.this could easily just be written in code though, no need to look at comments to the right of all your code.
comments simply aren't necessary if you have code written that way.Code:drawTwoCards(); if (sumOfFirstTwoCardsEquals(10)) { splitTheHand(); } if (sumOfCardsEquals(11)) { doubleDown(); } if (sumOfCardsLessThan(17) { drawAnotherCard(); }
Don't like it.
If I had to do code-review before commit, your code would not pass.
1) You use raw numbers in your code. That's an absolute no-no. Use constants. This makes it easier to understand where those numbers come from. And it makes it easier if you want to change a constant later, and you don't have to search for hundreds of occurences of the string "10".
2) The functionnames indicate what each step does. But your program does not indicate at all what it is trying to do. I'm not a cards player, I have no clue at all what problem this is supposed to solve. Or what algorithm is being used.
Why do I split when I get a sum of 10 ? What is "double down" ? What's special about the numbers 11 and 17 ? And again, what is this ? A nice block comment above this code could be a nice explanation.
For some reason, a majority of programmers thinks that they need to choose the shortest variable-name they can come up with. Wrong. Pick descriptive names. 20+ characters long if you have to. Do this for variables, functions, constants, everything.
FTFYyeah we already went over block comments going above functions being okay. if you weren't sure what the function double down does, you shouldn't be using it!
Don't like it.
If I had to do code-review before commit, your code would not pass.
1) You use raw numbers in your code. That's an absolute no-no. Use constants.
const int seventeen = 17;
if (GetSum() >= seventeen)
{
Stay()
}
else
{
DrawCard();
}
Code:const int seventeen = 17; if (GetSum() >= seventeen) { Stay() } else { DrawCard(); }![]()
I'm going to have to amend that to "Comment everything intelligently." Or "Comment everything descriptively."
I find them perfectly readable as long as they're not allmashedtogetherlikethis. Use _'s or -'s.IT'S ALSO DIFFICULT TO READ THINGS WRITTEN IN ALL CAPS
IT'S ALSO DIFFICULT TO READ THINGS WRITTEN IN ALL CAPS
That's the accepted standard for shell and environment variables.
Granted a language like bash isn't that pleasant to read to start with, but one persons opinions are likely based around a specific language and their experiences with it.
I've worked on enough projects with enough people to know that everybody has a different preference, as also evident in this thread. The best thing you can do as a programmer working on a team is adopt a set of practices that everybody uses regardless of having 100% agreement on the standard.
I think we all agree that all caps is difficult to read. This is the reason the forum never forces people to capitalize things, but the forum will automatically edit your post if you post in all caps.That's the accepted standard for shell and environment variables.
:thumbsup:The best thing you can do as a programmer working on a team is adopt a set of practices that everybody uses regardless of having 100% agreement on the standard.
It's forced if you use Visual Studio.The debate over should the '{' should go at the end of the line or the line below will never be settled amongst the programmers. But, the lead can make a decision and force it upon everyone!
if (conditon) {
stuff;
} else {
other_stuff;
}
I think we all agree that all caps is difficult to read. This is the reason the forum never forces people to capitalize things, but the forum will automatically edit your post if you post in all caps.
if (getSum() < seventeen)
if (getSum() < SEVENTEEN)
It's forced if you use Visual Studio.
I think a lot of it depends on the culture of the language. Perl tries to be as tight as possible, so you'll find a higher than average number of people putting the {} on the same line as other stuff:
Code:if (conditon) { stuff; } else { other_stuff; }
if (condition){
stuff;
}
vs.
if (condition)
{
stuff;
}
if(condition)
stuff;
else
stuff;
:thumbsup:constants should always be in all caps with a _ between the words imo.
I think we all agree that all caps is difficult to read.
It's rude.
Also harder to read, but primarily it's rude.
Or, work for a company that has a standard they require you to conform to, along with files that will auto format you code to meet them.
The debate over should the '{' should go at the end of the line or the line below will never be settled amongst the programmers. But, the lead can make a decision and force it upon everyone!
WHAT'S SO HARD...
Oh, sorry.What's so hard about reading all-caps? You see it every day on signs, advertisements, packaging, etc.
SPEED LIMIT
Most editors have the option of setting a different font. Most computer code is also viewed in a monospace font. (Which is (edit: one reason) why people [thread=2069847]should use code tags[/thread]!)
Code:SPEED LIMIT
That has some serifs on the "I" too. But looking over various fonts it seems to be difficult to make one that clearly distinguishes between "I", "l", "1", and "|" without some serifs.
Having serifs on the I's, 1's, and l's, like you said, are useful in telling them apart. All caps are only very readable when no serifs are involved or lots of kerning is used - read: not suitable for coding or most computer related typing without taking up lots of screen real estate for no return whatsoever.
Further, not everyone should have to change their default code editor font because someone doesn't understand why all caps is commonly atrocious.
I use Visual Studio every day. It isn't forced.
if (condition) {
if (condition)
{
Further, not everyone should have to change their default code editor font because someone doesn't understand why all caps is commonly atrocious.
