Questions tagged [programming-practices]

Programming Practices are the commonly or not so commonly used practices in development of software. These can include things like Agile Development, Kanban, Coding shortcuts, etc.

Filter by
Sorted by
Tagged with
279 votes
6 answers

Choosing between Single or multiple projects in a git repository?

In a git environment, where we have modularized most projects, we're facing the one project per repository or multiple projects per repository design issue. Let's consider a modularized project: ...
30 votes
4 answers

How to stop gold-plating and just be content to release working developments [closed]

The development team that I'm a member of has recently adapted to work according to Agile practices. This has personally highlighted the fact that I can't stop myself gold-plating code (and ...
135 votes
10 answers

Why do most of us use 'i' as a loop counter variable?

Has anyone thought about why so many of us repeat this same pattern using the same variable names? for (int i = 0; i < foo; i++) { // ... } It seems most code I've ever looked at uses i, j, k ...
45 votes
16 answers

Are there concrete reasons not to use libraries and code snippets heavily? [closed]

Overall I'm in programming for about 8 years now and it seems to me that I'm relying more and more on open source libraries and snippets (damn you GitHub!) to "get the job done". I know that in time I ...
105 votes
47 answers

Make a big deal out of == true?

There is a colleague of mine who constantly writes: if (someBool == true) It drives me up the wall! Should I make a big deal of it or just drop it?
99 votes
45 answers

What popular "best practices" are not always best, and why? [closed]

"Best practices" are everywhere in our industry. A Google search on "coding best practices" turns up nearly 1.5 million results. The idea seems to bring comfort to many; just follow the instructions,...
21 votes
6 answers

Efficient try / catch block usage?

Should catch blocks be used for writing logic i.e. handle flow control etc? Or just for throwing exceptions? Does it effect efficiency or maintainability of code? What are the side effects (if there ...
  • 313
90 votes
12 answers

How big does my project need to be for me to unit test it? [closed]

I assume that my project is decoupled enough to allow for unit testing. But how big, exactly, in terms of clases and functions does my project need to be to make unit testing worthwhile? We all make ...
  • 3,865
275 votes
14 answers

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
  • 2,639
186 votes
17 answers

How do you balance between "do it right" and "do it ASAP" in your daily work? [closed]

I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, ...
  • 2,182
87 votes
11 answers

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
  • 1,165
58 votes
9 answers

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; }...
12 votes
3 answers

Should a method do one thing and be good at it? [duplicate]

"Extract Till You Drop" is someting I've read in Uncle Bob's blog, meaning that a method should do one thing alone be good at it. What is that one thing? When should you stop extracting methods? ...
  • 961
181 votes
2 answers

Git branching and tagging best practices

I am currently learning to use Git by reading Pro Git. Right now I'm learning about branching and tags. My question is when should I use a branch and when should I use a tag? For example, say I ...
  • 2,379
126 votes
6 answers

Method vs Function vs Procedure

Simple question, but I often hear these three terms defined with such ferocity, but which have been known to me to mean different things over the years. What are the "correct" definitions of "...
30 votes
9 answers

if/else statements or exceptions [duplicate]

I don't know whether this question fits better on this site or on Stack Overflow, but because my question is connected rather to practices, that some specified problem. So, consider an object that ...
  • 639
25 votes
8 answers

Is every number in the code considered a "magic number"?

So every number in the code that we are sending to a method as an argument is considered as a Magic Number? To me, it shouldn't. I think if some number is let's say it is for minimum length of user ...
  • 839
18 votes
5 answers

When should you rewrite? [duplicate]

Possible Duplicate: When is a BIG Rewrite the answer? In Joel Spolsky's famous (or infamous) article Thins You Should Never Do, Part I, he makes the case that doing a rewrite is always a wrong ...
  • 421
3 votes
5 answers

What are the advantages of recursion compared to iteration? [duplicate]

I'm trying to understand when is preferred to use recursion rather than iteration. Actually I've encountered recursion only in Javascript but never in Python. I imagine that recursion should be used ...
  • 257
250 votes
16 answers

What's wrong with comments that explain complex code?

A lot of people claim that "comments should explain 'why', but not 'how'". Others say that "code should be self-documenting" and comments should be scarce. Robert C. Martin claims that (rephrased to ...
  • 20.8k
92 votes
7 answers

Short circuit evaluation, is it bad practice?

Something that I've known for a while but never considered is that in most languages it is possible to give priority to operators in an if statement based on their order. I often use this as a way to ...
  • 1,031
72 votes
11 answers

When to commit code?

When working on a project, the code may be developed reasonably fast in a single day or bit by bit for a prolonged period of few weeks/months/years. As code commits are becoming to be considered as a ...
user avatar
67 votes
16 answers

Best practice on if/return

I want to know what is considered better way of returning when I have if statement. Example 1: public bool MyFunction() { // Get some string for this example string myString = GetString(); ...
65 votes
17 answers

How to write correct loops?

Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Although I got my ...
  • 2,116
55 votes
3 answers

Which is a better practice - helper methods as instance or static?

This question is subjective but I was just curious how most programmers approach this. The sample below is in pseudo-C# but this should apply to Java, C++, and other OOP languages as well. Anyway, ...
  • 653
30 votes
3 answers

Is it considered a bad practice to add logic in a property setter?

I jumped in to a project and I see that the other developers are adding a lot of logic in the setters of synthesized properties. I understand how this works, but I think that it makes it hard to ...
  • 423
22 votes
8 answers

Is perfectionism a newbie's friend or enemy? [duplicate]

Possible Duplicate: Where do you draw the line for your perfectionism? I see that the development community is very focused on doing things the right way and personally I would like to do the ...
  • 657
237 votes
17 answers

Torvalds' quote about good programmer [closed]

Accidentally I've stumbled upon the following quote by Linus Torvalds: "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." I've thought ...
78 votes
17 answers

How to train yourself to avoid writing “clever” code? [closed]

Do you know that feeling when you just need to show off that new trick with Expressions or generalize three different procedures? This does not have to be on Architecture Astronaut scale and in fact ...
39 votes
6 answers

Should I place functions that are only used in one other function, within that function?

Specifically, I'm writing in JavaScript. Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
  • 493
33 votes
14 answers

Is using goto ever worthwhile?

goto is almost universally discouraged. Is using this statement ever worthwhile?
  • 7,622
31 votes
9 answers

Alternatives to the singleton pattern

I have read different opinions about the singleton pattern. Some maintain that it should be avoided at all costs and others that it can be be useful in certain situations. One situation in which I ...
  • 19.3k
15 votes
11 answers

How do you keep track of the authors of code? [closed]

This is something I was never taught. I have seen alot of different types of authoring styles. I code primarily in Java and Python. I was wondering if there was a standard authoring style or if ...
  • 2,084
11 votes
6 answers

Does context (like as an argument in a function) allow for numbers in code that aren't magic numbers? [duplicate]

I've been reading many of the articles and such about magic numbers, i.e. wikipedia article article It seemed like no one has considered context as a means of making it ...
6 votes
5 answers

When, if ever, should I daisy chain functions?

In a program divided up into many functions by which it is intended that they execute themselves one after another, when (if ever) is it preferred to: A) Execute the functions one after another in ...
  • 3,399
3 votes
3 answers

What kind of process should I use to learn a big system? [duplicate]

Possible Duplicate: How do you dive into large code bases? I just joined a new company and started to study one of the their bigger system. For me to be productive, I need to understand the ...
191 votes
15 answers

Why are the sizes of programs so large?

If we look at the vintage program Netscape Navigator or an early version of Microsoft Word, those programs were less than 50 MB in size. Now when I install google chrome it is 200 MB and desktop ...
105 votes
15 answers

Why are data structures so important in interviews? [closed]

I must confess that I was not so strong in data structures when I graduated out of college. Throughout the campus placements during my graduation, I've witnessed that most of the biggie tech companies ...
79 votes
15 answers

Is it possible to reach absolute zero bug state for large scale software?

I am talking about 20-30+ millions lines of code, software at the scale and complexity of Autodesk Maya for example. If you freeze the development as long as it needs to be, can you actually fix all ...
  • 1,950
54 votes
8 answers

Is it good that testers are competing to see who opens more bugs?

I'm a software developer. There is a team of testers who follow and run test cases written by the analyst, but also perform exploratory testing. It seems like the testers have been competing to see ...
50 votes
18 answers

What is proven as a good maximum length of a function? [closed]

Does function length affect the productivity of a programmer? If so, what is a good maximum number of lines to avoid productivity loss? Since this is a highly opinionated topic please back up the ...
45 votes
6 answers

How necessary is it to follow defensive programming practices for code that will never be made publicly available?

I'm writing a Java implementation of a card game, so I created a special type of Collection I'm calling a Zone. All modification methods of Java's Collection are unsupported, but there's a method in ...
  • 1,654
44 votes
11 answers

Logging: Why and What? [closed]

I've never written programs which make significant use of logging. The most I've done is to capture stack traces when exceptions happen. I was wondering, how much do other people log? Does it depend ...
42 votes
8 answers

Private variable vs property?

When setting a value to a variable inside of a class most of the time we are presented with two options: private string myValue; public string MyValue { get { return myValue; } set { myValue = ...
  • 2,129
35 votes
13 answers

Why should a class be anything other than "abstract" or "final/sealed"?

After 10+ years of java/c# programming, I find myself creating either: abstract classes: contract not meant to be instantiated as-is. final/sealed classes: implementation not meant to serve as base ...
33 votes
6 answers

Try/Catch/Log/Rethrow - Is Anti Pattern?

I can see several post where importance of handling exception at central location or at process boundary been emphasized as a good practice rather than littering every code block around try/catch. I ...
32 votes
17 answers

Am I copy/paste programmer? [duplicate]

When ever I am stuck with a particular problem, I search for a solution in Google. And then I try to understand the code and tweak it according to my requirement. For example recently I had asked a ...
30 votes
5 answers

When and why you should use void (instead of e.g. bool/int)

I occasionally run into methods where a developer chose to return something which isn't critical to the function. I mean, when looking at the code, it apparently works just as nice as a void and after ...
29 votes
3 answers

What is decoupling and what development areas can it apply to? [closed]

I recently noticed decoupling as a topic in a question, and want to know what it is and where it can apply. By "where can it apply", I mean: Is it only relevant where compiled languages like C and ...
user avatar
23 votes
11 answers

Refactor or Concentrate on Completing App

Would you refactor your app as you go or focus on completing app first? Refactoring will mean progress of app app will slow down. Completing app will mean you get a possibly very hard to maintain app ...
  • 2,251

2 3 4 5