The Lounge is rated PG. If you're about to post something you wouldn't want your
kid sister to read then don't post it. No flame wars, no abusive conduct, no programming
questions and please don't post ads.
1. Comments. Too often have I seen comments that made no sense, were outdated, wrong or overly obvious. In fact I've learned to ignore comments as they've never helped me in any way. I guess programmers can't write English...
2. Code that is copy-pasted. Often the cause of bugs.
3. Swallowing exceptions.
4. Non-Object Oriented code in Object Oriented languages.
5. Formatting, you've said it.
6. Not using brackets in if statements. Very dangerous...
I'm working for a company that has worked with VB since the start. The first employees have worked with VB even longer and used Clipper before that.
I've seen 1 through 5 all to often
I've come to hate 6 when we started doing C# and outsourced a project to another company. HORRIBLE!!! I read the code and didn't know if they meant it that way or if they had introduced subtle bugs...
A lot of samples I get from the internet have it too.
I probably forgot some stuff, but these are a few of my least-favourite things.
I like to mark other's code with the unsafe keyword. That's what it is for, after all.
Really bad things:
- Stringly typing
- Similar to magic numbers: Literal values and strings all over the place instead of enums, resources or similar.
- Spaghetti code, or totally insanely structured code
- Global variables, including abuse of the session or caches
- managing data in dozens of separate variables instead of using even the most primitive kind of entity
- not understanding the framework, being unwilling to learn and contaminating the code with flawed homebrew solutions
Ooh, good thread. Not ones I'm guilty of, but ones I call out in code reviews, that I haven't seen covered elsewhere in this thread:
0. Implementing code that's already part of the framework
1. Explicit path creation (rather than using Path.Combine)
2. Lines that are too long
3. Overly complex lines; these are normally ones that combine numerous statements together using ternary and coalescing null operators (it's a sure sign that someone has Resharper installed).
4. Talking about R#, converting clear code into a muddied part ordinary syntax, part LINQ abomination that you cannot remember what it does so you have to spend 20 minutes figuring out the damn thing.
5. Oh, and while we're at it with LINQ, myList.Where(p=> p.Id == aUniqueId).FirstOrDefault(); This one's a twofer - first of all, if it's a unique number, use SingleOrDefault not FirstOrDefault - you're only getting one value back. Secondly, learn how to use the power of LINQ, that Where statement is redundant so the statement can become myList.SingleOrDefault(p => p.Id == aUniqueId);
6. Not checking inputs into methods for validity.
7. When testing code, not asserting that something has happened.
8. Unnecessary try/catch blocks.
9. Blindly consuming exceptions - I'll have no On Error Resume Next behaviour please.
10. Not checking for null. I once saw a production system go boom because while the main code was properly checking nulls, the code that was reporting out that it couldn't do something because of null values didn't check the value out that it was attempting to log; thus blowing up the system.
That's not all, but that should be enough to be getting on with.
Secondly, learn how to use the power of LINQ, that Where statement is redundant so the statement can become myList.SingleOrDefault(p => p.Id == aUniqueId);
However, using Where(predicate).function rather than Function(predicate) is significantly faster.
Incidentally a straight forward While loop is more efficient than either.
So if efficiency is a concern (and we're not just talking close here, there's a big enough difference that it counts!) you need to be careful!
var found = collectionClass.FirstOrDefault(i => i.Field == searchValue);
var found = collectionClass.Where(i => i.Field == searchValue).FirstOrDefault();
foreach(item in collectionClass)
if (item.Field = searchValue)
found = item;
The results for 100,000 collection with 100,000 searches?
Oh - I see. I didn't do that - the figures were from a test I did some time ago when someone kept going through our code base changing all the .where(predicate).something() to .something(predicate) because they said it was more efficient - which I didn't think was the case.
As part of No. 4 in your strangely numbered list (starting at 1!)
4a) Putting anything but the bare minimum in Setters/Getters - part of the project I am working on lives in permanent side-effect hell because some getters access the database to get values (and don't cache them) and some setters access otehr properties that access properties that access properties - and all of them have side effects
0. Method Names that don't match their function, or do more than their function
Team work often brings out the best (and the worst) in people. My peeves are about devs who indulge in:
1. Sending an email to the dev in the next cubicle instead of simply having a chat
2. Refusing to commit code until it is "perfect"
3. Making working code not work in the name of "refactoring"
4. Spending a week perfecting the latest LINQ statement and being unable to debug or optimise the thing
5. Deciding mid-project to change data access
6. Bitching about FXCop
7. Logging? What logging?
9. Read the spec - real devs don't read specs!
My two fav's are: Inline braces and swallowing exceptions
There's another side to this. Excessive check ins. You don't need to check in every single change every time you make the change - wait until you have a logical break and then check it in. I've seen people check in every 5 minutes, just checking in things like colour or border thickness changes. It wouldn't be so bad if the next checkin wasn't for the next colour.
1) Leaving Edits in the code (Edits are messages that often pop up in developmental purposes for our in-house testing)
2) Bad tabbing. Don't blame me, really. I use a different tabbing structure due to the program we use doesn't automatically tab things well.