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
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 ...
3
votes
3answers
217 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 ...
1
vote
3answers
347 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): ...
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 ...
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 ...
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 ...
-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 ...
-4
votes
2answers
152 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 = ...
-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 ...
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 ...
0
votes
4answers
54 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....
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 ...
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 ...
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 ...
0
votes
2answers
269 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 ...
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 ...
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
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 ...
0
votes
1answer
156 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 ...
0
votes
1answer
97 views

One-field interfaces

I have an interface with only one title field: protocol Artist { var title: String { get } } (A) Should I pass the whole object as I did here: class Album { func setArtist(_ artist: Artist) ...
2
votes
1answer
76 views

Sharing Docstrings between similar functions?

Assuming we have different classes with methods that possess the exact same description, however execute code a bit differently for the same return type. class Foo: """This is the Foo class ...
0
votes
3answers
129 views

Is is worth the time to create a list of manual regression tests for a legacy application?

I am part of a new dev team that is assigned to work on a legacy app. The app currently has no regression or automated unit, integration and system tests. Due to technical debt and convoluted ...
0
votes
2answers
142 views

Should I track my handled exceptions?

Various analytics tools will track the number of handled and unhandled exceptions (crashes) that happen in an app. This obviously helps us find problems we didn't know existed and will fix it. Quite ...
2
votes
2answers
182 views

How to organize my test functions? (Part II: Keepin' it classy)

What are the best practices to organize your unit tests in classes? I see different possibilities: 1) One would be to write one "container" class for each function you want test and then ...
5
votes
2answers
88 views

Is there some sort of standardisation for error reporting? [closed]

I'm looking for some sort of standardisation, in a similar vein as POSIX for compatibility and familiarity between different commandline-interfaces, but for error reporting. Notably, I'm looking for: ...
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 ...
8
votes
4answers
386 views

Should detected vulnerabilities in old commits be remedied?

One of my projects on GitHub has received a vulnerability alert, in this case of moderate severity. The vulnerability has been detected in a dependency of an old version of the code. Current versions ...
2
votes
1answer
44 views

Where to keep Ansible Inventory file

I keep my Ansible based deployment module in the same repository/directory as my application code. I use Mercurial for my VCS. The inventories file is ephemeral as the IP's of the cloud hosts keep on ...
0
votes
0answers
53 views

Getting into situations that requires mixin while building classes. How should I correct my class design?

I have the following classes for to solve a particular problem related to HTTP responses. Problem is for class ServerSentEventStreamResponseService I am in a situation where I need mixin because I ...
-1
votes
2answers
161 views

Null checks good practice if code will only be ran when object is never null

Using a website with Javascript as example. Let's say I have script A which only performs a specific function on page Foo. For example something like sorting elements in a list. Script A is only ...
-2
votes
1answer
87 views

Unit Tests - correct approach to test system with multiple layers

I'm wondering about Unit Tests. Let say i got a code ( in C#, but language is not important here): public class SOT: ISOT { List<string> _internalCollection = new List<string>(); ...
-2
votes
1answer
67 views

What is a common name for a module being tested?

When writing unit tests, I want to reduce the cognitive load of the reader as much as possible. One thing I've noticed that bothers me is that the variable names of the thing that is being tested are ...
2
votes
5answers
255 views

How do you force developers to define dependencies/arguments if it's bad to put the constructor function in the interface?

I just started reading more about OOP and its design patterns and is confused with this conceptual question. I am too new that I am having second thought that the proper title should be, "when is it ...
28
votes
6answers
2k views

Turning a personal Python project into a releasable library

I'm an academic rather than a programmer, and I have many years' experience writing Python programs for my own use, to support my research. My latest project is likely to be useful to many others as ...
0
votes
1answer
74 views

Folder structure for child classes

I have a user feature. user feature also has other subfeatures user application details and user contact information. Usually, because application details and contact information are part of user ...
24
votes
8answers
4k views

On a once a day user action: 24 Hours Reset vs. Midnight Reset [closed]

When a user is able to perform an action only once a day, for example getting a free ticket for a competition, there are two possibilities I came across in my experience. 1) 24 Hours Reset If he ...
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 ...
0
votes
2answers
79 views

SVN / Git How to administer branches

I'm the technical lead for a small company (6 developers). We currently use SVN and we're slowly porting over to Git, after everyone gets their training. Currently our clients are the ones who "pull ...
133
votes
17answers
13k 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 ...
1
vote
1answer
155 views

Using “On” at the start of a method name

From what I've observed, methods that start with the word "On" fall into two categories: A base class that defines an event will expose a protected method whose name starts with "On" followed by the ...
1
vote
1answer
152 views

Where and how to connect to external API in my service class?

In my service class I would like to connect to external API. Where and how should I do it? 1) Inject in constructor ExternalClass and assign to private property. Next in other property in constructor ...
1
vote
1answer
43 views

Dictionary Application: Suggestions for serialization format and data structure

I want to create a dictionary application. One of the design guideline is performance in querying and showing up the definitions of words. I would like some suggestions on two design choices: Which ...
3
votes
3answers
411 views

Are there any drawbacks to using a nested class instead of declaring a new one?

I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class. From reviewing the code, it seems like the nested ...