Skip to main content
281 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
276 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
  • 210k
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.6k
158 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
  • 59.9k
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 ...
tmaj's user avatar
  • 1,713
119 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
  • 52.7k
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
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
  • 210k
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.5k
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,955
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.3k
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
  • 210k
66 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
  • 7,590
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
  • 210k
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.8k
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

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

I would happily start the project over. You're a student, and you're still learning. This puts you in a very different position than the question you linked to. You have no professional ...
Hylianpuffball's user avatar
55 votes
Accepted

Should you use a library when you can do the task without it?

As an engineer, perhaps it is suitable to think of this as an optimization problem. Naturally we must have an optimization goal. A common one in this sort of situation would be to minimize Total Cost ...
John Wu's user avatar
  • 26.6k
55 votes

What is the most efficient way to continue developing a piece of software in the long-term?

Let me speed you up by slowing you down. Ever heard who the best person is to hire as a tutor? It’s not the teacher. It’s some student who just took the class. Who remembers the struggle. Therefor I ...
candied_orange's user avatar
53 votes

Is it common to have to iterate on a design due to overlooking problems with it?

Iterating through multiple versions of a design is a great thing to do! It is rare to create a design that has all the good properties at the first try. As software engineers, we should be humble and ...
Euphoric's user avatar
  • 37.5k
52 votes
Accepted

Are init() methods a code smell?

Yes, it's a code smell. A code smell isn't something that necessarily always needs to get removed. It's something that makes you take a second look. Here you have an object in two fundamentally ...
Karl Bielefeldt's user avatar
48 votes

At what point is brevity no longer a virtue?

Brevity is good when it reduces clutter around the things that matter, but when it becomes terse, packing too much relevant data too densely to easily follow, then the relevant data becomes clutter ...
Mason Wheeler's user avatar
48 votes
Accepted

Split the calculation of return value and the return statement in one-line methods?

Introducing explaining variables is a well-known refactoring which can sometimes help to make complicated expressions better readable. However, in the shown case, the additional variable does not "...
Doc Brown's user avatar
  • 210k
44 votes

How to argue against lowering quality standards for legacy codebase?

Me, myself, and I, have been both a producer and maintainer of legacy code. If your tool's generating "thousands of violations" (or even hundreds for that matter), forget the tool, it's inapplicable ...
John Forkosh's user avatar
44 votes

Why should we reuse code as binary modules instead of copy/pasting?

Copying code (causing duplication) and sharing code (de-duplicating it via shared modules, classes, libraries, whatever) each have their benefits and drawbacks. In my opinion, the key difference is in ...
Alexander's user avatar
  • 4,954

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