Skip to main content

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
283 votes
6 answers
167k views

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: ...
Johan Sjöberg's user avatar
31 votes
4 answers
9k views

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 ...
Andy Bowskill's user avatar
135 votes
10 answers
105k views

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
14k views

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 ...
Henrik P. Hessel's user avatar
105 votes
47 answers
76k views

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?
98 votes
45 answers
29k views

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,...
22 votes
6 answers
13k views

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 ...
HashimR's user avatar
  • 323
90 votes
12 answers
9k views

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 ...
Lamin Sanneh's user avatar
  • 4,045
276 votes
14 answers
124k views

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 ...
Slamice's user avatar
  • 2,657
187 votes
17 answers
16k views

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, ...
Flot2011's user avatar
  • 2,192
88 votes
11 answers
18k views

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 ...
liortal's user avatar
  • 1,175
59 votes
9 answers
49k views

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; }...
Daniel Kaplan's user avatar
14 votes
3 answers
16k views

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? ...
KyelJmD's user avatar
  • 981
251 votes
16 answers
49k views

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 ...
Aviv Cohn's user avatar
  • 21.4k
187 votes
2 answers
225k views

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 ...
Code-Guru's user avatar
  • 2,449
127 votes
6 answers
163k views

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 "...
Django Reinhardt's user avatar
68 votes
17 answers
23k views

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 ...
CodeYogi's user avatar
  • 2,176
68 votes
16 answers
68k views

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(); ...
30 votes
9 answers
51k views

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 ...
Thaven's user avatar
  • 659
25 votes
8 answers
11k views

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 ...
Blake's user avatar
  • 839
18 votes
5 answers
4k views

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 ...
BIBD's user avatar
  • 421
3 votes
5 answers
7k views

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 ...
G M's user avatar
  • 273
93 votes
7 answers
16k views

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 ...
innova's user avatar
  • 1,041
73 votes
11 answers
28k views

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
56 votes
3 answers
72k views

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, ...
Ilian's user avatar
  • 663
31 votes
3 answers
5k views

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 ...
phi's user avatar
  • 433
22 votes
8 answers
5k views

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 ...
Akromyk's user avatar
  • 667
237 votes
17 answers
133k views

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 ...
79 votes
17 answers
11k views

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 ...
42 votes
6 answers
13k views

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 ...
Gary's user avatar
  • 523
36 votes
14 answers
31k views

Is using goto ever worthwhile?

goto is almost universally discouraged. Is using this statement ever worthwhile?
Casebash's user avatar
  • 7,672
35 votes
10 answers
33k views

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 ...
Giorgio's user avatar
  • 19.7k
15 votes
11 answers
20k views

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 ...
myusuf3's user avatar
  • 2,084
11 votes
6 answers
2k views

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 programmers.stackexchange.com article It seemed like no one has considered context as a means of making it ...
superbAfterSemperPhi's user avatar
8 votes
5 answers
8k views

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 ...
Anon's user avatar
  • 3,603
3 votes
3 answers
665 views

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 ...
user394128's user avatar
191 votes
15 answers
39k views

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 ...
Niklas Rosencrantz's user avatar
105 votes
15 answers
120k views

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 ...
81 votes
15 answers
62k views

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 ...
Joan Venge's user avatar
  • 1,970
68 votes
8 answers
8k views

If I need to use a piece of memory throughout the lifespan of my program, is it really necessary to free it right before program termination?

In many books and tutorials, I've heard the practice of memory management stressed and felt that some mysterious and terrible things would happen if I didn't free memory after I'm done using it. I ...
CaptainObvious's user avatar
53 votes
8 answers
9k views

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 ...
Only a Curious Mind's user avatar
52 votes
18 answers
47k views

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 ...
49 votes
10 answers
16k views

Why are exceptions considered better than explicit error testing? [duplicate]

Possible Duplicate: Defensive Programming vs Exception Handling? if/else statements or exceptions I often come across heated blog posts where the author uses the argument: "exceptions vs ...
Richard Keller's user avatar
46 votes
6 answers
7k views

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 ...
codebreaker's user avatar
  • 1,734
44 votes
11 answers
29k views

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 ...
Winston Ewert's user avatar
42 votes
8 answers
45k views

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 = ...
Edward's user avatar
  • 2,179
39 votes
6 answers
35k views

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 ...
rahulaga-msft's user avatar
36 votes
4 answers
21k views

Are exceptions for flow control best practice in Python?

I'm reading "Learning Python" and have come across the following: User-defined exceptions can also signal nonerror conditions. For instance, a search routine can be coded to raise an exception ...
J B's user avatar
  • 469
36 votes
3 answers
91k views

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
36 votes
13 answers
5k views

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 ...
Nicolas Repiquet's user avatar

1
2 3 4 5