305 votes

Should we avoid language features that C++ has but Java doesn't?

No. This is woefully and terribly misguided. Java features are not somehow better than C++ features, especially in a vacuum. If your programmers don't know how to use a feature, train or hire better ...
Telastyn's user avatar
  • 109k
282 votes

Prevent deprecated code from compiling after reaching a deadline

This would constitute a feature known as a time bomb. DON'T CREATE TIME BOMBS. Code, no matter how well you structure and document it, will turn into an ill-understood near-mythical black box if it ...
Kilian Foth's user avatar
275 votes
Accepted

A large part of my code has a major design flaw. Finish it off or fix it now?

If I were in your shoes, I would probably try it this way: first, finish the current project - at least partially - as soon as possible, but in a working state. Probably you need to reduce your ...
Doc Brown's user avatar
  • 206k
180 votes
Accepted

Should I add redundant code now just in case it may be needed in the future?

As an exercise, first let's verify your logic. Though as we'll see, you have bigger problems than any logical problem. Call the first condition A and the second condition B. You first say: ...
Eric Lippert's user avatar
  • 46.1k
177 votes
Accepted

How can I maintain code quality without SCM?

You can loosely replicate the role source control plays with three simple tools: Back-up software (Commits/Check-ins) Folders (Branches) Performing a directory merge between two directories using a ...
Greg Burghardt's user avatar
164 votes
Accepted

At what point is brevity no longer a virtue?

To answer your question about extant research But has anything been written or researched on recognizing the point where striving for code brevity stops being useful and becomes a barrier to ...
John Wu's user avatar
  • 26.4k
159 votes

How do huge open source libraries get maintained while having code far from "clean code" practices?

The principles stated in "Clean Code" are not always generally agreed upon. Most of it is common sense, but some of the author's opinions are rather controversial and not shared by everybody. In ...
JacquesB's user avatar
  • 58.7k
143 votes

Should we avoid language features that C++ has but Java doesn't?

Just because the syntax seems similar on the surface doesn't mean that the two languages are compatible. 1, 4 and 5 are really the same question: Now, I'm no fan of C++, but saying "Code without C++ ...
Luaan's user avatar
  • 1,850
139 votes

How can I maintain code quality without SCM?

Although the consensus would certainly be to not work for this company I don't believe that really answers your question. You can't really replace SCM. You might not need the usual bells and ...
Erdrik Ironrose's user avatar
122 votes
Accepted

In what cases is less code not better?

A thin person isn't necessarily healthier than an overweight person. A 980 lines children story is easier to read than a 450 lines physics thesis. There are many attributes that determine the ...
M.A. Hanin's user avatar
120 votes

A large part of my code has a major design flaw. Finish it off or fix it now?

Finished IT projects, even faulty ones, are much better than unfinished ones. Unfinished ones can teach you a lot too, but not as much as finished ones. You may not see it now, but you get an ...
tymtam's user avatar
  • 1,713
118 votes
Accepted

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Firstly, magic values are avoided in programming by using variables or constants. CSS does not support variables, so even if magic values were frowned on, you don't have much of a choice (except using ...
JacquesB's user avatar
  • 58.7k
117 votes
Accepted

Functions that simply call another function, bad design choice?

Never forget the Law of Demeter: The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs. In its general form, ...
Flater's user avatar
  • 48.7k
94 votes

Should we avoid language features that C++ has but Java doesn't?

I will answer your questions in order. If Java doesn't provide a feature that C++ has, it means that the feature is not good, so we should prevent using it. Yes, any feature not present in Java is ...
Yakk's user avatar
  • 2,211
94 votes

Should developers fix bugs in their own code?

This seems more a failure of your code review process than who is fixing the bugs. If the anti-patterns in the code and faulty assumptions that don’t get reworked aren't getting called out and ...
Philip Kendall's user avatar
89 votes

Should I add redundant code now just in case it may be needed in the future?

What you are doing in the code you're showing above is not so much future proofing as much as it is defensive coding. Both if statements test for different things. Both are appropriate tests ...
Adam Zuckerman's user avatar
87 votes

Is it acceptable to copy and paste long but straightforward code instead of wrapping them into a class or function?

You need to consider the cost of change. What if you wanted to change how connections are made? How easy would it be? If you have a lot of duplicated code, then finding all the places that need ...
Vaughn Cato's user avatar
  • 1,069
87 votes
Accepted

How to deal with 'almost good' code from a junior developer?

If you think the code should be fixed before merging, make comments. Preferably with "why" so the dev can learn. Keep in mind code is read far more often than written. So things which seem "minor" ...
enderland's user avatar
  • 12.1k
83 votes
Accepted

How do huge open source libraries get maintained while having code far from "clean code" practices?

Good answer here already, but let me say a word about your butterknife example: though I have no idea what the code does, at a first glance, it does not look really unmaintainable to me. Variables and ...
Doc Brown's user avatar
  • 206k
83 votes
Accepted

In code review, should I ask to do a refactor outside of the scope in a pull request?

There are several relevant trade-offs here: Review complexity. If a branch has more than one functional change commit or more than one refactoring commit it becomes time-consuming to review the ...
l0b0's user avatar
  • 11.4k
79 votes

Why are large amounts of magic numbers acceptable in CSS and SVGs?

It's acceptable because these formats are not code, but data. If you were to remove all the "magic numbers," you would essentially duplicate every label, and end up with ridiculous looking files like:...
Karl Bielefeldt's user avatar
73 votes
Accepted

How to argue against lowering quality standards for legacy codebase?

Code is just a means to an end. What that end might be varies, but typically it's profit. If it is profit; then to successfully argue anything you want to show that it will improve profit - e.g. by ...
Brendan's user avatar
  • 3,925
71 votes

Prevent deprecated code from compiling after reaching a deadline

In C# you would use the ObsoleteAttribute in the following manner: In version 1, you ship the feature. A method, class, whatever. In version 2, you ship a better feature intended to replace the ...
Eric Lippert's user avatar
  • 46.1k
67 votes
Accepted

In C, if I am passing a file descriptor to a function, should I close it in the function or in the place where I called the function?

In most languages, including C, we usually produce the most maintainable code by dealing with acquire / free at the same level: fd = open(...) consume(fd); close(fd); This applies to ...
J_H's user avatar
  • 6,530
66 votes
Accepted

Inverting an IF statement

It depends. In your example having the non-inverted if statement is not a problem, because the body of the if is very short. However you usually want to invert the statements when the bodies grow. We ...
Andy's user avatar
  • 10.3k
66 votes
Accepted

Is setRGBColor(32,128,192) a valid use of magic number?

Any kind of GUI framework I have seen which uses RGB colors has a datatype for that. So I would recommend to define a constant like RGBColor DARKER_BLUE(32,128,192); and use it accordingly label-&...
Doc Brown's user avatar
  • 206k
62 votes
Accepted

Prevent deprecated code from compiling after reaching a deadline

I don't think this would be a useful feature when it really prohibits compilation. When at 01/06/2018 large parts of the code won't compile which compiled the day before, your team will quickly remove ...
Doc Brown's user avatar
  • 206k
60 votes

How to communicate that insertion order matters in a map?

So use LinkedHashMap. Yes, you should use Map over a specific implementation whenever possible, and yes, this is best practice. That said, this is an oddly specific situation where the ...
Neil's user avatar
  • 22.7k
57 votes

Dry running a function

You're doing multiple different things in that function. Start off by splitting it into separate functions. Here's an example using a closure for the "dry run" function. function ...
8bittree's user avatar
  • 5,656
56 votes

Should we avoid language features that C++ has but Java doesn't?

I'm just gonna answer your reasons: I don't understand how you come to that conclusion. Different languages have different features. Depends on scope, architecture of language, sometimes preferences ...
Simon's user avatar
  • 1,774

Only top scored, non community-wiki answers of a minimum length are eligible