Most Popular

1500 questions
305
votes
19 answers

Are #regions an antipattern or code smell?

C# allows the use of #region/#endregion keywords to make areas of code collapsible in the editor. Whenever I do this though I do it to hide large chunks of code that could probably be refactored into other classes or methods. For example I have seen…
Craig
  • 4,302
  • 3
  • 21
  • 21
302
votes
5 answers

Is there any reason to use the "var" keyword in ES6?

Babel's guide to ES6 says: let is the new var. Apparently the only difference is that var gets scoped to the current function, while let gets scoped to the current block. There are some good examples in this answer. I can't see any reason to use…
callum
  • 10,377
  • 9
  • 30
  • 33
302
votes
19 answers

Should I return from a function early or use an if statement?

I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why. public void SomeFunction(bool someCondition) { if (someCondition) { // Do Something } } or public…
Rachel
  • 23,979
  • 16
  • 91
  • 159
301
votes
38 answers

How Can I Know Whether I Am a Good Programmer?

Like most people, I think of myself as being a bit above average in my field. I get paid well, I've gotten promotions, and I've never had a real problem getting good references or getting a job. But I've been around enough to notice that many of…
Kristopher Johnson
  • 1,719
  • 4
  • 15
  • 15
301
votes
20 answers

What does SVN do better than Git?

No question that the majority of debates over programmer tools distill to either personal choice (by the user) or design emphasis, that is, optimizing design according to particular uses cases (by the tool builder). Text editors are probably the…
doug
  • 568
  • 2
  • 5
  • 12
298
votes
6 answers

Why squash git commits for pull requests?

Why does every serious Github repo I do pull requests for want me to squash my commits into a single commit? I thought the git log was there so you could inspect all your history and see exactly what changes happened where, but squashing it pulls it…
hamstar
  • 3,091
  • 2
  • 11
  • 6
295
votes
9 answers

Aggregation vs Composition

I understand what composition is in OOP, but I am not able to get a clear idea of what Aggregation is. Can someone explain?
Vinoth Kumar C M
  • 15,455
  • 23
  • 57
  • 86
295
votes
16 answers

Grokking Java culture - why are things so heavy? What does it optimize for?

I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use Java (I can't go into details). Java syntax is no…
Mikhail Ramendik
  • 1,549
  • 2
  • 9
  • 11
294
votes
2 answers

Python file naming convention?

I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example of each, should the filenames be all lower case…
darkace
  • 3,051
  • 3
  • 10
  • 5
294
votes
8 answers

Why are people making tables with divs?

In modern web development I'm coming across this pattern ever more often. It looks like this:
Vilx-
  • 5,320
  • 4
  • 20
  • 24
293
votes
14 answers

How do you unit test private methods?

I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
Vinoth Kumar C M
  • 15,455
  • 23
  • 57
  • 86
291
votes
17 answers

Is premature optimization really the root of all evil?

A colleague of mine today committed a class called ThreadLocalFormat, which basically moved instances of Java Format classes into a thread local, since they are not thread safe and "relatively expensive" to create. I wrote a quick test and…
Craig Day
  • 563
  • 3
  • 5
  • 5
291
votes
7 answers

Does using == in JavaScript ever make sense?

In JavaScript, the Good Parts, Douglas Crockford wrote: JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect. If the two operands are of the same type and have the…
Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
287
votes
39 answers

Why don't all companies buy developers the best hardware?

I must be missing something. The cost of employing a programmer in my area is $50 to $100 an hour. A top end machine is only $3,000, so the cost of buying a truly great computer every three years comes to $0.50/hour. ($3000/(150 wks * 40…
Eric Wilson
  • 12,071
  • 9
  • 50
  • 77
282
votes
22 answers

Leaving intentional bugs in code for testers to find

We don't do this at our firm, but one of my friends says that his project manager asked every developer to add intentional bugs just before the product goes to QA. This is how it works: Just before the product goes to QA, the development team adds…
Krishnabhadra
  • 2,440
  • 2
  • 15
  • 14