Reputation: 1502206
This is definitely subjective, but I'd like to try to avoid it becoming argumentative. I think it could be an interesting question if people treat it appropriately.
The idea for this question came from the comment thread from my answer to the "What are five things you hate about your favorite language?" question. I contended that classes in C# should be sealed by default - I won't put my reasoning in the question, but I might write a fuller explanation as an answer to this question. I was surprised at the heat of the discussion in the comments (25 comments currently).
So, what contentious opinions do you hold? I'd rather avoid the kind of thing which ends up being pretty religious with relatively little basis (e.g. brace placing) but examples might include things like "unit testing isn't actually terribly helpful" or "public fields are okay really". The important thing (to me, anyway) is that you've got reasons behind your opinions.
Please present your opinion and reasoning - I would encourage people to vote for opinions which are well-argued and interesting, whether or not you happen to agree with them.
Upvotes: 363
Views: 312686
Reputation: 405955
According to the amount of feedback I've gotten, my most controversial opinion, apparently, is that programmers don't always read the books they claim to have read. This is followed closely by my opinion that a programmer with a formal education is better than the same programmer who is self-taught (but not necessarily better than a different programmer who is self-taught).
Upvotes: 6
Reputation:
Don't use stored procs in your database.
The reasons they were originally good - security, abstraction, single connection - can all be done in your middle tier with ORMs that integrate lots of other advantages.
This one is definitely controversial. Every time I bring it up, people tear me apart.
Upvotes: 11
Reputation: 4040
Avoid indentation.
Use early returns, continues or breaks.
instead of:
if (passed != NULL)
{
for(x in list)
{
if (peter)
{
print "peter";
more code.
..
..
}
else
{
print "no peter?!"
}
}
}
do:
if (pPassed==NULL)
return false;
for(x in list)
{
if (!peter)
{
print "no peter?!"
continue;
}
print "peter";
more code.
..
..
}
Upvotes: 40
Reputation:
If a developer cannot write clear, concise and grammatically correct comments then they should have to go back and take English 101.
We have developers and (the horror) architects who cannot write coherently. When their documents are reviewed they say things like "oh, don't worry about grammatical errors or spelling - that's not important". Then they wonder why their convoluted garbage documents become convoluted buggy code.
I tell the interns that I mentor that if you can't communicate your great ideas verbally or in writing you may as well not have them.
Upvotes: 31
Reputation: 17775
SESE (Single Entry Single Exit) is not law
Example:
public int foo() {
if( someCondition ) {
return 0;
}
return -1;
}
vs:
public int foo() {
int returnValue = -1;
if( someCondition ) {
returnValue = 0;
}
return returnValue;
}
My team and I have found that abiding by this all the time is actually counter-productive in many cases.
Upvotes: 101
Reputation:
Opinion: SQL is code. Treat it as such
That is, just like your C#, Java, or other favorite object/procedure language, develop a formatting style that is readable and maintainable.
I hate when I see sloppy free-formatted SQL code. If you scream when you see both styles of curly braces on a page, why or why don't you scream when you see free formatted SQL or SQL that obscures or obfuscates the JOIN condition?
Upvotes: 380
Reputation: 5393
Women make better programmers than men.
The female programmers I've worked with don't get wedded to "their" code as much as men do. They're much more open to criticism and new ideas.
Upvotes: 3
Reputation: 22493
Code layout does matter
Maybe specifics of brace position should remain purely religious arguments - but it doesn't mean that all layout styles are equal, or that there are no objective factors at all!
The trouble is that the uber-rule for layout, namely: "be consistent", sound as it is, is used as a crutch by many to never try to see if their default style can be improved on - and that, furthermore, it doesn't even matter.
A few years ago I was studying Speed Reading techniques, and some of the things I learned about how the eye takes in information in "fixations", can most optimally scan pages, and the role of subconsciously picking up context, got me thinking about how this applied to code - and writing code with it in mind especially.
It led me to a style that tended to be columnar in nature, with identifiers logically grouped and aligned where possible (in particular I became strict about having each method argument on its own line). However, rather than long columns of unchanging structure it's actually beneficial to vary the structure in blocks so that you end up with rectangular islands that the eye can take in in a single fixture - even if you don't consciously read every character.
The net result is that, once you get used to it (which typically takes 1-3 days) it becomes pleasing to the eye, easier and faster to comprehend, and is less taxing on the eyes and brain because it's laid out in a way that makes it easier to take in.
Almost without exception, everyone I have asked to try this style (including myself) initially said, "ugh I hate it!", but after a day or two said, "I love it - I'm finding it hard not to go back and rewrite all my old stuff this way!".
I've been hoping to find the time to do more controlled experiments to collect together enough evidence to write a paper on, but as ever have been too busy with other things. However this seemed like a good opportunity to mention it to people interested in controversial techniques :-)
[Edit]
I finally got around to blogging about this (after many years parked in the "meaning to" phase): Part one, Part two, Part three.
Upvotes: 72
Reputation: 45101
Programmers who don't code in their spare time for fun will never become as good as those that do.
I think even the smartest and most talented people will never become truly good programmers unless they treat it as more than a job. Meaning that they do little projects on the side, or just mess with lots of different languages and ideas in their spare time.
(Note: I'm not saying good programmers do nothing else than programming, but they do more than program from 9 to 5)
Upvotes: 873
Reputation: 2561
C++ is one of the WORST programming languages - EVER.
It has all of the hallmarks of something designed by committee - it does not do any given job well, and does some jobs (like OO) terribly. It has a "kitchen sink" desperation to it that just won't go away.
It is a horrible "first language" to learn to program with. You get no elegance, no assistance (from the language). Instead you have bear traps and mine fields (memory management, templates, etc.).
It is not a good language to try to learn OO concepts. It behaves as "C with a class wrapper" instead of a proper OO language.
I could go on, but will leave it at that for now. I have never liked programming in C++, and although I "cut my teeth" on FORTRAN, I totally loved programming in C. I still think C was one of the great "classic" languages. Something that C++ is certainly NOT, in my opinion.
Cheers,
-R
EDIT: To respond to the comments on teaching C++. You can teach C++ in two ways - either teaching it as C "on steroids" (start with variables, conditions, loops, etc), or teaching it as a pure "OO" language (start with classes, methods, etc). You can find teaching texts that use one or other of these approaches. I prefer the latter approach (OO first) as it does emphasize the capabilities of C++ as an OO language (which was the original design emphasis of C++). If you want to teach C++ "as C", then I think you should teach C, not C++.
But the problem with C++ as a first language in my experience is that the language is simply too BIG to teach in one semester, plus most "intro" texts try and cover everything. It is simply not possible to cover all the topics in a "first language" course. You have to at least split it into 2 semesters, and then it's no longer "first language", IMO.
I do teach C++, but only as a "new language" - that is, you must be proficient in some prior "pure" language (not scripting or macros) before you can enroll in the course. C++ is a very fine "second language" to learn, IMO.
-R
'Nother Edit: (to Konrad)
I do not at all agree that C++ "is superior in every way" to C. I spent years coding C programs for microcontrollers and other embedded applications. The C compilers for these devices are highly optimized, often producing code as good as hand-coded assembler. When you move to C++, you gain a tremendous overhead imposed by the compiler in order to manage language features you may not use. In embedded applications, you gain little by adding classes and such, IMO. What you need is tight, clean code. You can write it in C++, but then you're really just writing C, and the C compilers are more optimized in these applications.
I wrote a MIDI engine, first in C, later in C++ (at the vendor's request) for an embedded controller (sound card). In the end, to meet the performance requirements (MIDI timings, etc) we had to revert to pure C for all of the core code. We were able to use C++ for the high-level code, and having classes was very sweet - but we needed C to get the performance at the lower level. The C code was an order of magnitude faster than the C++ code, but hand coded assembler was only slightly faster than the compiled C code. This was back in the early 1990s, just to place the events properly.
-R
Upvotes: 100
Reputation: 16398
Programmers should never touch Word (or PowerPoint)
Unless you are developing a word or a document processing tool, you should not touch a Word processor that emits only binary blobs, and for that matter:
Generated XML files are binary blobs
Programmers should write plain text documents. The documents a programmer writes need to convey intention only, not formatting. It must be producible with the programming tool-chain: editor, version-control, search utilities, build system and the like. When you are already have and know how to use that tool-chain, every other document production tool is a horrible waste of time and effort.
When there is a need to produce a document for non-programmers, a lightweight markup language should be used such as reStructuredText (if you are writing a plain text file, you are probably writing your own lightweight markup anyway), and generate HTML, PDF, S5, etc. from it.
Upvotes: 3
Reputation: 40679
My most controversial programming opinion is that finding performance problems is not about measuring, it is about capturing.
If you're hunting for elephants in a room (as opposed to mice) do you need to know how big they are? NO! All you have to do is look. Their very bigness is what makes them easy to find! It isn't necessary to measure them first.
The idea of measurement has been common wisdom at least since the paper on gprof (Susan L. Graham, et al 1982)*, when all along, right under our noses, has been a very simple and direct way to find code worth optimizing.
As a small example, here's how it works. Suppose you take 5 random-time samples of the call stack, and you happen to see a particular instruction on 3 out of 5 samples. What does that tell you?
............. ............. ............. ............. .............
............. ............. ............. ............. .............
Foo: call Bar ............. ............. Foo: call Bar .............
............. Foo: call Bar ............. ............. .............
............. ............. ............. Foo: call Bar .............
............. ............. ............. ............. .............
............. .............
It tells you the program is spending 60% of its time doing work requested by that instruction. Removing it removes that 60%:
...\...../... ...\...../... ............. ...\...../... .............
....\.../.... ....\.../.... ............. ....\.../.... .............
Foo: \a/l Bar .....\./..... ............. Foo: \a/l Bar .............
......X...... Foo: cXll Bar ............. ......X...... .............
...../.\..... ...../.\..... ............. Foo: /a\l Bar .............
..../...\.... ..../...\.... ............. ..../...\.... .............
/ \ .../.....\... / \ .............
Roughly.
If you can remove the instruction (or invoke it a lot less), that's a 2.5x speedup, approximately. (Notice - recursion is irrelevant - if the elephant's pregnant, it's not any smaller.) Then you can repeat the process, until you truly approach an optimum.
Some people use this whenever they have a performance problem, and don't understand what's the big deal.
Most people have never heard of it, and when they do hear of it, think it is just an inferior mode of sampling. But it is very different, because it pinpoints problems by giving cost of call sites (as well as terminal instructions), as a percent of wall-clock time. Most profilers (not all), whether they use sampling or instrumentation, do not do that. Instead they give a variety of summary measurements that are, at best, clues to the possible location of problems. Here is a more extensive summary of the differences.
*In fact that paper claimed that the purpose of gprof was to "help the user evaluate alternative implementations of abstractions". It did not claim to help the user locate the code needing an alternative implementation, at a finer level then functions.
My second most controversial opinion is this, or it might be if it weren't so hard to understand.
Upvotes: 22
Reputation: 12015
Coding is an Art
Some people think coding is an art, and others think coding is a science.
The "science" faction argues that as the target is to obtain the optimal code for a situation, then coding is the science of studying how to obtain this optimal.
The "art" faction argues there are many ways to obtain the optimal code for a situation, the process is full of subjectivity, and that to choose wisely based on your own skills and experience is an art.
Upvotes: 10
Reputation: 31300
Zealous adherence to standards stands in the way of simplicity.
MVC is over-rated for websites. It's mostly just VC, sometimes M.
Upvotes: 4
Reputation: 2963
Programmers need to talk to customers
Some programmers believe that they don't need to be the ones talking to customers. It's a sure way for your company to write something absolutely brilliant which no one can work out what it's for or how it was intended to be used.
You can't expect product managers and business analysts to make all the decisions. In fact, programmers should be making 990 out of the 1000 (often small) decisions that go into creating a module or feature, otherwise the product would simply never ship! So make sure your decisions are informed. Understand your customers, work with them, watch them use your software.
If you're going the write the best code, you want people to use it. Take an interest in your user base and learn from the "dumb idiots" who are out there. Don't be afraid, they'll actually love you for it.
Upvotes: 5
Reputation: 33759
Lower camelCase is stupid and unsemantic
Using lower camelCase makes the name/identifier ("name" used from this point) look like a two-part thing. Upper CamelCase however, gives the clear indication that all the words belong together.
Hungarian notation is different ... because the first part of the name is a type indicator, and so it has a separate meaning from the rest of the name.
Some might argue that lower camelCase should be used for functions/procedures, especially inside classes. This is popular in Java and object oriented PHP. However, there is no reason to do that to indicate that they are class methods, because BY THE WAY THEY ARE ACCESSED it becomes more than clear that these are just that.
Some code examples:
# Java
myobj.objMethod()
# doesn't the dot and parens indicate that objMethod is a method of myobj?
# PHP
$myobj->objMethod()
# doesn't the pointer and parens indicate that objMethod is a method of myobj?
Upper CamelCase is useful for class names, and other static names. All non-static content should be recognised by the way they are accessed, not by their name format(!)
Here's my homogenous code example, where name behaviours are indicated by other things than their names... (also, I prefer underscore to separate words in names).
# Java
my_obj = new MyObj() # Clearly a class, since it's upper CamelCase
my_obj.obj_method() # Clearly a method, since it's executed
my_obj.obj_var # Clearly an attribute, since it's referenced
# PHP
$my_obj = new MyObj()
$my_obj->obj_method()
$my_obj->obj_var
MyObj::MyStaticMethod()
# Python
MyObj = MyClass # copies the reference of the class to a new name
my_obj = MyObj() # Clearly a class, being instantiated
my_obj.obj_method() # Clearly a method, since it's executed
my_obj.obj_var # clearly an attribute, since it's referenced
my_obj.obj_method # Also, an attribute, but holding the instance method.
my_method = myobj.obj_method # Instance method
my_method() # Same as myobj.obj_method()
MyClassMethod = MyObj.obj_method # Attribute holding the class method
MyClassMethod(myobj) # Same as myobj.obj_method()
MyClassMethod(MyObj) # Same as calling MyObj.obj_method() as a static classmethod
So there goes, my completely obsubjective opinion on camelCase.
Upvotes: 5
Reputation: 57158
Python does everything that other programming languages do in half the dev time... and so does Google!!! Check out Unladen Swallow if you disagree.
Wait, this is a fact. Does it still qualify as an answer to this question?
Upvotes: 1
Reputation: 8923
small code is always better, but then complex ?: instead of if-else made me realize that sometime large code is more readable.
Upvotes: 4
Reputation: 19247
Relational database systems will be the best thing since sliced bread...
... when we (hopefully) get them, that is. SQL databases suck so hard it's not funny.
What I find amusing (if sad) is certified DBAs who think an SQL database system is a relational one. Speaks volumes for the quality of said certification.
Confused? Read C. J. Date's books.
edit
Why is it called Relational and what does that word mean?
These days, a programmer (or a certified DBA, wink) with a strong (heck, any) mathematical background is an exception rather than the common case (I'm an instance of the common case as well). SQL with its tables, columns and rows, as well as the joke called Entity/Relationship Modelling just add insult to the injury. No wonder the misconception that Relational Database Systems are called that because of some Relationships (Foreign Keys?) between Entities (tables) is so pervasive.
In fact, Relational derives from the mathematical concept of relations, and as such is intimately related to set theory and functions (in the mathematical, not any programming, sense).
[http://en.wikipedia.org/wiki/Finitary_relation][2]:
In mathematics (more specifically, in set theory and logic), a relation is a property that assigns truth values to combinations (k-tuples) of k individuals. Typically, the property describes a possible connection between the components of a k-tuple. For a given set of k-tuples, a truth value is assigned to each k-tuple according to whether the property does or does not hold.
An example of a ternary relation (i.e., between three individuals) is: "X was-introduced-to Y by Z", where (X,Y,Z) is a 3-tuple of persons; for example, "Beatrice Wood was introduced to Henri-Pierre Roché by Marcel Duchamp" is true, while "Karl Marx was introduced to Friedrich Engels by Queen Victoria" is false.
Wikipedia makes it perfectly clear: in a SQL DBMS, such a ternary relation would be a "table", not a "foreign key" (I'm taking the liberty to rename the "columns" of the relation: X = who, Y = to, Z = by):
CREATE TABLE introduction (
who INDIVIDUAL NOT NULL
, to INDIVIDUAL NOT NULL
, by INDIVIDUAL NOT NULL
, PRIMARY KEY (who, to, by)
);
Also, it would contain (among others, possibly), this "row":
INSERT INTO introduction (
who
, to
, by
) VALUES (
'Beatrice Wood'
, 'Henri-Pierre Roché'
, 'Marcel Duchamp'
);
but not this one:
INSERT INTO introduction (
who
, to
, by
) VALUES (
'Karl Marx'
, 'Friedrich Engels'
, 'Queen Victoria'
);
Relational Database Dictionary:
relation (mathematics) Given sets s1, s2, ..., sn, not necessarily distinct, r is a relation on those sets if and only if it's a set of n-tuples each of which has its first element from s1, its second element from s2, and so on. (Equivalently, r is a subset of the Cartesian product s1 x s2 x ... x sn.)
Set si is the ith domain of r (i = 1, ..., n). Note: There are several important logical differences between relations in mathematics and their relational model counterparts. Here are some of them:
- Mathematical relations have a left-to-right ordering to their attributes.
- Actually, mathematical relations have, at best, only a very rudimentary concept of attributes anyway. Certainly their attributes aren't named, other than by their ordinal position.
- As a consequence, mathematical relations don't really have either a heading or a type in the relational model sense.
- Mathematical relations are usually either binary or, just occasionally, unary. By contrast, relations in the relational model are of degree n, where n can be any nonnegative integer.
- Relational operators such as JOIN, EXTEND, and the rest were first defined in the context of the relational model specifically; the mathematical theory of relations includes few such operators.
And so on (the foregoing isn't meant to be an exhaustive list).
Upvotes: 8
Reputation: 8065
80% of bugs are introduced in the design stage.
The other 80% are introduced in the coding stage.
(This opinion was inspired by reading Dima Malenko's answer. "Development is 80% about the design and 20% about coding", yes. "This will produce code with near zero bugs", no.)
Upvotes: 2
Reputation: 4267
Simplicity Vs Optimality
I believe its very difficult to write code that's both simple and optimal.
Upvotes: 1
Reputation: 2835
Development is 80% about the design and 20% about coding
I believe that developers should spend 80% of time designing at the fine level of detail, what they are going to build and only 20% actually coding what they've designed. This will produce code with near zero bugs and save a lot on test-fix-retest cycle.
Getting to the metal (or IDE) early is like premature optimization, which is know to be a root of all evil. Thoughtful upfront design (I'm not necessarily talking about enormous design document, simple drawings on white board will work as well) will yield much better results than just coding and fixing.
Upvotes: 3
Reputation: 40679
Manually halting a program is an effective, proven way to find performance problems.
Believable? Not to most. True? Absolutely.
Programmers are far more judgmental than necessary.
Witness all the things considered "evil" or "horrible" in these posts.
Programmers are data-structure-happy.
Witness all the discussions of classes, inheritance, private-vs-public, memory management, etc., versus how to analyze requirements.
Upvotes: 5
Reputation: 6843
I often get shouted down when I claim that the code is merely an expression of my design. I quite dislike the way I see so many developers design their system "on the fly" while coding it.
The amount of time and effort wasted when one of these cowboys falls off his horse is amazing - and 9 times out of 10 the problem they hit would have been uncovered with just a little upfront design work.
I feel that modern methodologies do not emphasize the importance of design in the overall software development process. Eg, the importance placed on code reviews when you haven't even reviewed your design! It's madness.
Upvotes: 26
Reputation: 19247
C++ is future killer language...
... of dynamic languages.
nobody owns it, has a growing set of features like compile-time (meta-)programming or type inference, callbacks without the overhead of function calls, doesn't enforce a single approach (multi-paradigm). POSIX and ECMAScript regular expressions. multiple return values. you can have named arguments. etc etc.
things move really slowly in programming. it took JavaScript 10 years to get off the ground (mostly because of performance), and most of people who program in it still don't get it (classes in JS? c'mon!). i'd say C++ will really start shining in 15-20 years from now. that seems to me like about the right amount of time for C++ (the language as well as compiler vendors) and critical mass of programmers who today write in dynamic languages to converge.
C++ needs to become more programmer-friendly (compiler errors generated from templates or compile times in the presence of same), and the programmers need to realize that static typing is a boon (it's already in progress, see other answer here which asserts that good code written in a dynamically typed language is written as if the language was statically typed).
Upvotes: 1
Reputation: 7157
Associative Arrays / Hash Maps / Hash Tables (+whatever its called in your favourite language) are the best thing since sliced bread!
Sure, they provide fast lookup from key to value. But they also make it easy to construct structured data on the fly. In scripting languages its often the only (or at least most used) way to represent structured data.
IMHO they were a very important factor for the success of many scripting languages.
And even in C++ std::map and std::tr1::unordered_map helped me writing code faster.
Upvotes: 1
Reputation: 81342
Intranet Frameworks like SharePoint makes me think the whole corporate world is one giant ostrich with its head in the sand
I'm not only talking about MOSS here, I've worked with some other CORPORATE INTRANET products, and absolutely not one of them are great, but SharePoint (MOSS) is by far the worst.
EVERYONE STILL CONTINUES TO USE AND PURCHASE SHAREPOINT, AND MANAGERS STILL TRY VERY HARD TO PRETEND ITS NOT SATANS SPAWN.
Microformats
Using CSS classes originally designed for visual layout - now being assigned for both visual and contextual data is a hack, loads of ambiguity. Not saying the functionality should not exist, but fix the damn base language. HTML wasn't hacked to produce XML - instead the XML language emerged. Now we have these eager script kiddies hacking HTML and CSS to do something it wasn't designed to do, thats still fine, but I wish they would keep these things to themselves, and no make a standard out of it. Just to some up - butchery!
Upvotes: 10