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
68
votes
15answers
43k 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 ...
0
votes
1answer
228 views

Can a class factory also save the object to a database?

How can a factory also save the object in the database? I want to create an object that consists of other objects. Pseudocode: firstObject = db.get....; secondObject = db.get....; expectedObject = ...
1
vote
0answers
70 views

Is using a non-compile-time-constant value as a default parameter a code smell? [duplicate]

I'm trying to use App.config and Configuration Manager for the first time. I wanted to use some values in App.config as default parameters for some methods, but this results in an error (not a compile ...
6
votes
6answers
2k views

Should you create a boolean function that does the opposite of an existing function just so its purpose is clear?

Based on this question. Would you consider it best practice to create a function that does the opposite of an existing function just to give it a different name. Example: If you already have bool ...
3
votes
3answers
220 views

Which is a better method name? GetById(int id) or Get(int id) [closed]

Has there ever been a consensus on which convention is "better": User.GetById(int id); or User.Get(int id); i.e., is User.Get(int id); not descriptive enough? Or does is the parameter implication ...
1
vote
0answers
101 views

Circular dependence and many references to the same object

I have tried to design a class diagram for my first game. But then I realized that there are some ugly parts. First, there is reference from StateSystem to State and from State to StateSystem. The ...
236
votes
16answers
43k 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 ...
1
vote
3answers
349 views

Why shouldn't I create a class for every property?

In a particular program I had written, I noticed I had a few classes with this pattern: class IdObject: '''Objects with generated id properties''' def __init__(self, id_generator): ...
13
votes
6answers
3k views

Is it bad practice to store metadata information in file names? Better solutions?

I have noticed where I work people are keen on storing information in file names, and parsing the file names. To me this doesn't seem to be especially good practice. I already see the occasional ...
16
votes
6answers
4k views

What is a macro? Difference between macro and function?

I do not understand the macro concept well. What is a macro? I do not understand how is it different from function? Both function and macro contain a block of code. So how does macro and function ...
3
votes
1answer
164 views

What file ownership/permissions should I set for the files/directories before open sourcing a project?

I have multiple projects in different programming languages that I will upload on online code hosting platforms as Open Source projects. What file permissions and ownerships should I set on the files ...
4
votes
7answers
1k views

How do you know where you stopped in your codes after a 2-week break? [closed]

I just had a more than 2-week long vacation/business trip and I couldn't remember actually what was I working in my coding and where I stopped. Could someone recommend a best practice to solve this?
0
votes
0answers
44 views

Synchronization data between API (server) and local database : C#

I hit an API which gives a list of chairs with their location. I save this data in my local database. Whenever I received updated data like add a new chair, update location of the chairs and delete a ...
0
votes
5answers
8k views

Is it a good practice to wrap collection in Java? [closed]

I came across a snippet like this, and find it's over engineering. Is it a good practice? public class SchoolList extends ArrayList<School> { } public class School extends ArrayList<...
24
votes
5answers
26k views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
14
votes
11answers
5k 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 ...
-1
votes
1answer
257 views

What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
1
vote
2answers
76 views

RESTful API - Adding nested resources as a query parameter?

I recently had thoughts on handling the flat vs nested architecture when designing a RESTful API. Would there be anything wrong with having a system where your nested resources can be specified ...
-4
votes
1answer
87 views

Multi-level random selection implementation [closed]

Structure I have a structure like this: level 1 items represented by a capital letter (A, B, C, D,...) level 2 items represented by lower case letter (a, b, c, d,...) level 3 items repredented ...
10
votes
2answers
3k views

Exceptions in DDD

I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
15
votes
2answers
998 views

How do you deal with comprehending abstraction in code?

When looking at a new codebase I like to start from a bottom-up approach. Where I comprehend one file and then move up to the next abstraction. But often times I find myself forgetting what the ...
63
votes
22answers
6k views

Why do some programmers think there is a contrast between theory and practice? [closed]

Comparing software engineering with civil engineering, I was surprised to observe a different way of thinking: any civil engineer knows that if you want to build a small hut in the garden you can just ...
-4
votes
4answers
128 views

Creating one function for multiple purposes vs multiple functions for one purpose each [closed]

I have one function that is used to compute distances of an object in 3 different ways. Is one of the following two methods considered better practice: Creating 3 different functions, one each for ...
-4
votes
2answers
153 views

What is the proper way to unspecify an integer's value in C++? [closed]

// Default initialization int i; // i has an unspecified value return i; // Probably 0, but Unreliable i = 5; // i has a specified value i = int();// This will give it a specified value, 0 i = ...
48
votes
14answers
46k views

Do most programmers copy and paste code? [closed]

I learned very early on that cutting & pasting somebody else's code takes longer in the long run that writing it yourself. In my opinion unless you really understand it, cut & paste code will ...
3
votes
4answers
319 views

Why don't we put import statements at the bottom of source files [closed]

My point is that the actual code is more important than import statements. I often don't even need to change or see the import statements. Also, when I'm refactoring code, I usually finish changing ...
4
votes
5answers
3k views

Methods of ordering function definitions in code

When I work on some programming project (usually command line application in Python with many switches), I'm usually creating about 30 and more functions. Most of the functions are in one file (except ...
0
votes
4answers
55 views

Extent of Administrator Capabilities: HR and Design Logistics?

So I am developing an employee management application on behalf of a company and am concerned about the extent of rights and capabilities that are to be bestowed upon registered administrator accounts....
16
votes
6answers
18k views

Is it a bad habit to (over)use reflection?

Is it a good practice to use reflection if greatly reduces the quantity of boilerplate code? Basically there is a trade-off between performance and maybe readability on one side and abstraction/...
35
votes
12answers
18k views

If XML is so bad…why do so many people use it? [closed]

I understand the purpose of XML, but I always hear people complain about how BAD it is? I don't really understand whats so bad about it? I usually hear the terms "bloated" and "slow" tossed around. ...
30
votes
4answers
4k views

When should a commit not be version tagged?

Context: I recently found out about Semantic Versioning, and am trying to determine how to best use it practically for my own projects. Given that semver takes major changes, minor changes, and ...
2
votes
4answers
2k views

Should I avoid using spaces in my filenames?

I sometimes find experienced programmers who will actively avoid using spaces in their filenames, opting to use underscores or camelCase instead. (i.e. /org map/attach jobs.cpp vs /org_map/...
1
vote
5answers
343 views

Passing Objects vs. Primitives

What is the best practice when it comes to passing variables around? Is it better to pass objects (models) or is it better to pass primitives that will be required by the called method? What are the ...
1
vote
3answers
212 views

What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals

If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
1
vote
2answers
123 views

Observer reporting to multiple layers up from the bottom of hierarchy

There is a swarm of objects. When a new unit of certain kind appears on the frame, the swarm integrates this object by calling some add_new_unit method. Above the swarm is a controller abstraction, ...
2
votes
1answer
197 views

Which programming pattern is best for checking which partition a number lies in?

I have an interval partitioned into “MECE” subintervals, and I want to check which subinterval a number lies in. (MECE stands for “mutually exclusive & collectively exhaustive”, meaning the ...
9
votes
5answers
582 views

Best Practice - Wrapping if around function call vs Adding early exit if guard in function

I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax. I'm not asking what is the best approach when in a function, I am ...
4
votes
5answers
384 views

How to deal with getting stuck on solo projects [closed]

There are a few questions similar to this one but I feel the situation is a little different because I do not have the methods available to me or they are not working. I have been working on a solo ...
0
votes
2answers
157 views

Should execution continue if array is empty?

Just a general programming best practices question. If I have a function like that takes in an array of items and the function then calls a series of other functions which filter and act on the items ...
39
votes
7answers
32k views

Is it a bad practice to have an interface to define constants?

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and ...
0
votes
2answers
271 views

Is using Objects.requireNonNull() in production bad practice?

Objects.requireNonNull is a helpful method to spot NullPointerExceptions effectively while developing. But in fact it's throwing a RuntimeException which could crash the application (the worst thing ...
1
vote
3answers
190 views

What is difference between assigning to auto-Implemented properties VS their backing fields within the class

Before I started using auto-implemented properties, I was taught that when assigning properties in the constructor (because of the potential of making a property read only), I should assign directly ...
5
votes
3answers
5k views

Should a Java Boolean be used for ternary (3-state) logic?

I'm trying to make a basic cache of a boolean value, and I did it like such: private Boolean _valueCache = null; private boolean getValue() { try { if (_valueCache == null) { // if cache ...
64
votes
17answers
20k 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 ...
19
votes
5answers
2k views

Can a programming language by design enforce “clean code”? [closed]

So I'm coding my first projects in C++ and it seems that it takes more effort to make the code "clean", rather than merely work. I.e. it seems as if C++ "allows" to write ugly, but working code. ...
2
votes
2answers
1k views

Are the over-usage of delegates a bad thing?

Good day. I have been told that a good practice for writing methods is to make the method only responsible for doing one thing. It made sense to me now that I look back upon it in retrospect. There ...
2
votes
3answers
173 views

Design - What is the best way to separate functionalities?

I recently worked on a file explorer within a console window (like Midnight Commander). I want to use ncurses as library. I have encountered some fundamental problems with my design and searched on ...
14
votes
7answers
6k views

A defense for boilerplate?

To me, boilerplate code is obviously bad. However I've met a developer who displays resistance in any attempt to reduce boilerplate. I realized I didn't have a readily formed, well thought out ...
221
votes
6answers
103k 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: ...
0
votes
1answer
157 views

Methods linking bad/good practices

I have multiple methods calling each other to simplify changing anything in the code and to avoid fixing errors and copy pasting. It looks like this: Is this a bad practice? Does it cause too much ...