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.
1,595 questions
13
votes
7
answers
3k
views
How to code properly when you're used to relying on ChatGPT for solutions?
I’m a programming student, and I have a problem that’s holding me back. In my first year, we coded in Pascal, and back then, AI tools like ChatGPT weren’t as popular. But starting from my second year, ...
1
vote
1
answer
238
views
Internal data representation in firmware
I'm developing firmware for control system.
That system will collect data from different sensors (using ADC, GPIO, I2C temperature sensors, etc.), process this data and generate some control signals.
...
308
votes
16
answers
137k
views
Why are shortcuts like x += y considered good practice?
I have no idea what these are actually called, but I see them all the time. The Python implementation is something like:
x += 5 as a shorthand notation for x = x + 5.
But why is this considered good ...
277
votes
14
answers
126k
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 ...
123
votes
12
answers
48k
views
Why are multiple programming languages used in the development of one product or piece of software?
I am a recent grad student aiming to start my Master's in Computer Science. I have come across multiple open source projects that really intrigue me and encourage me to contribute to them (CloudStack, ...
249
votes
16
answers
50k
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 ...
296
votes
16
answers
30k
views
Grokking Java culture - why are things so heavy? What does it optimize for? [closed]
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 ...
69
votes
17
answers
24k
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 ...
26
votes
8
answers
6k
views
What is a good way to indicate that a number is not something you can count with?
What is a good way to indicate in programming that the sequence of digits you see is not a value you can do math on?
I use a lot of numbers which aren't "numbers". From account-numbers to ...
25
votes
13
answers
10k
views
How much time should you spend planning a commit before writing code?
At the moment I'm spending more time planning out a commit than actually writing code when adding a new feature. Less than two hours would be lucky, and sometimes I'd spend a good part of the day ...
97
votes
53
answers
10k
views
Harmful temptations in programming
Just curious, what kinds of temptations in programming turned out to be really harmful in your projects?
Like when you really feel the urge to do something and you believe it's going to benefit the ...
138
votes
17
answers
15k
views
How do I know how reusable my methods should be? [closed]
I am minding my own business at home and my wife comes to me and says
Honey.. Can you print all the Day Light Savings around the world for 2018 in the console? I need to check something.
And I am ...
134
votes
14
answers
22k
views
Should the solution be as generic as possible or as specific as possible?
Say I have a entity that has "type" attribute. There could be 20+ possible types.
Now I'm asked to implement something that would allow changing the type from A->B, which is the only use case.
So ...
191
votes
15
answers
40k
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 ...
126
votes
27
answers
10k
views
What are the worst false economies in software development? [closed]
What are the worst false economies (that is ways of saving money that ultimately cost more than they save) prevalent in the software industry and how do you combat them?
98
votes
45
answers
30k
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,...
23
votes
6
answers
6k
views
How important is it to clearly understand requirements and architecture before starting to code? [closed]
Whenever possible I have been requiring an understanding of the requirements and architecture for the next scope of work before starting to code.
Sometimes due to schedule pressure on larger projects ...
244
votes
16
answers
21k
views
Project is nearly done, but procedural spaghetti code. Do I rewrite or just keep trying to ship it? [closed]
I'm a beginner web developer (one year of experience).
A couple of weeks after graduating, I got offered a job to build a web application for a company whose owner is not much of a tech guy. He ...
130
votes
15
answers
30k
views
Are single-character constants better than literals?
I recently encountered a class which provides pretty much every single-character as a constant; everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary; I read an "article" which ...
10
votes
4
answers
5k
views
Is there something between Debug and Release build?
Specifically with CMake builds, if you don't specify a build type explicitly, the build will use neither Debug nor Release compilation flags.
I was writing my own Makefile for a simple program and ...
282
votes
6
answers
169k
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:
...
184
votes
17
answers
25k
views
Is there a benefit in compiling your code as you go along?
I recently had a job interview in which they gave me an hour to write some real code. It wasn't a huge amount, probably less than 100 lines. After about 45 minutes, I compiled, ran it, and got it to ...
52
votes
90
answers
27k
views
What should every programmer know about programming?
Please, stay on technical issues, avoid behavior, cultural, career or political issues.
0
votes
4
answers
282
views
Use-cases for Expression<TDelegate> except translating to another language?
So I just learned about Expression<TDelegate>. As a library author this really intrigued me; my libraries make extensive use of source generators to generate both high-performance code and code ...
5
votes
5
answers
1k
views
Is it bad practice to use nullptr in ternary operation?
I've set up a ternary operator in place of a pile of if-else's, the final expression being nullptr in order to finish the loop, like so:
int menuSelect;
std::string operation="";
(...
237
votes
17
answers
137k
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 ...
94
votes
7
answers
18k
views
Short circuit evaluation, is it bad practice?
In most languages it is possible to give priority to operators in an if statement based on order. I use this as a way to prevent null reference exceptions, e.g.:
if (smartphone != null && ...
105
votes
47
answers
77k
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?
118
votes
16
answers
24k
views
Should I add redundant code now just in case it may be needed in the future?
Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use ...
94
votes
14
answers
9k
views
How can I avoid always feeling like if I completely rebuilt my program from scratch I'd do it much better? [closed]
I have learned a significant amount of coding, however, it's always been in a scientific environment (not computer science), completely self-taught without anyone to guide me in the right direction. ...
152
votes
22
answers
26k
views
Stuck due to "knowing too much" [closed]
Note more discussion at http://news.ycombinator.com/item?id=4037794
I have a relatively simple development task, but every time I try to attack it, I end up spiraling in deep thoughts - how could it ...
133
votes
19
answers
17k
views
Can a function be too short?
Whenever I find myself writing the same logic more than once, I usually stick it in a function so there is only one place in my application I have to maintain that logic. A side effect is that I ...
96
votes
13
answers
13k
views
How to warn other programmers of class implementation
I'm writing classes that "must be used in a specific way" (I guess all classes must...).
For example, I create the fooManager class, which requires a call to, say, Initialize(string,string). ...
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, ...
64
votes
10
answers
31k
views
Why would a program use a closure?
After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure?
...
53
votes
15
answers
36k
views
Clean Code: Functions with few parameters [closed]
I read the first chapters of Clean Code by Robert C. Martin, and it seems to me it's pretty good, but I have a doubt, in one part it is mentioned that it is good (cognitively) that the functions ...
48
votes
6
answers
10k
views
Why is 2FA usually done after the correct password has been provided?
If all accounts have 2FA for a given product, is there any reason why the 2FA box couldn't be on the primary login screen? Is it bad practice to request 2FA code along with username and password on ...
42
votes
40
answers
7k
views
Stuff you should have learned in school but didn't pay attention to at the time [closed]
This question made me think that there was a better question to ask.
What did you learn in school that you didn't care about at the time, but turned out to be useful or you had to relearn in the ...
39
votes
8
answers
10k
views
Is it ok copying code from one application to another, both belonging to the same repository, to keep them independent?
Given a repository which contains two different applications A and B (e.g. bootloader and RTOS), is it ok to copy source code from A to B in order to avoid dependencies (include's, adding A source ...
24
votes
10
answers
7k
views
What does the crash early concept mean?
While I am reading The Pragmatic Programmer e2, I came across Tip 38: Crash Early. Basically, the author, at least to my understanding, advises to avoid catching exceptions and let the program crash. ...
-1
votes
6
answers
1k
views
Proving program correctness under all possible cases
There are techniques of proving program correctness under all possible
cases, but that is a more advanced topic, for a later subject in your
curriculum.
I always had this doubt:
Is it possible to ...
135
votes
10
answers
107k
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 ...
81
votes
15
answers
64k
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 ...
20
votes
8
answers
23k
views
Is an empty 'while' loop bad practice?
Consider the following:
public boolean maybeUpdateTime() {
if (this.timeReference.isAfter(lastInterval.getBeginning()) {
this.timeReference = lastInterval.getEnd();
lastInterval = ...
52
votes
18
answers
49k
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 ...
105
votes
15
answers
121k
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 ...
-2
votes
1
answer
216
views
Best Practices for Managing Multiple Entity Types in ASP.NET Core
I'm working on an ASP.NET Core application that requires handling multiple types of a single entity. Each type has its own properties and validation rules, which has led to confusion and complexity in ...
129
votes
11
answers
33k
views
How has an increase in the complexity of systems affected successive generations of programmers?
As a "new" programmer (I first wrote a line of code in 2009), I've noticed it's relatively easy to create a program that exhibits quite complex elements today with things like .NET framework for ...
140
votes
5
answers
166k
views
Two HTML elements with same id attribute: How bad is it really?
Just browsing the google maps source code. In their header, they have 2 divs with id="search" one contains the other, and also has jstrack="1" attribute. There is a form separating them like so:
<...
-1
votes
1
answer
186
views
Testability when API contract is fixed
Recently, I spoke to an Engineering Manager about some work I've done:
I had to implement a micro-service to a third party API contract (that they will call). Part of the requirement is to ...