We’re rewarding the question askers & reputations are being recalculated! Read more.

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
36 views

How to decide if a global variable is used inside or outside a function in Python?

In Python variables that are created outside of a function are known as global variables. However to create a global variable inside a function (a local variable), you can use the global keyword. My ...
2
votes
4answers
153 views

When is it appropriate to reuse a method for another method?

I am writing a program that describes different properties on a single Management Company's plot of land. For this program there are 3 overloaded addProperty method's. My question is I can reuse the ...
0
votes
2answers
140 views

Is it wrong to build as much granularity as possible into a REST API?

I was recently considering the difference between using raw SQL and using a query builder like knex.js for writing dynamic queries so that I get any level of granularity for filtering database tables. ...
1
vote
2answers
296 views

Calling methods on objects VS. passing objects as parameters

Which is considered a generally accepted practice? class Image { public void decode(); }; //main Image image; image.decode(); vs class ImageDecoder { public Image run(Image image); }; //main Image ...
-1
votes
1answer
52 views

Function returning dynamic value [closed]

Imagine you have a chain of functions calls, in which each function is taking the previous function's output as input for the next calculation in the chain. Make an assumption that you are leading ...
-3
votes
2answers
92 views

How to take notes on programming techniques? Competitive Programming Tips [closed]

More specifically, how to study competitive programming, but starting with the notes. Some background information: So I am new to programming. I noticed that competitive programming is a lot like ...
3
votes
4answers
365 views

How to use Macros in Programming to make code faster, efficient and compact

Recently I was going through some of the solutions of the best competitive programmers in the world. I found out that those people use a template while writing the programs, preferably in C++. I ...
0
votes
2answers
88 views

Negation of sameness is confirmation of difference [closed]

De Morgan's laws: the negation of a disjunction is the conjunction of the negations; and the negation of a conjunction is the disjunction of the negations; or, the same: not (A or B) = not A and ...
-2
votes
1answer
44 views

Property file, annotations or database tables for storing configurations

Which one is better property file, annotations or database tables for storing configurations related to a program? What are the advantages/disadvantages and what use cases are best suited for each ...
2
votes
1answer
243 views

Guard block moved to the bottom [closed]

Sometimes it is a good idea to have a guard block: https://softwareengineering.stackexchange.com/a/157413 https://en.wikipedia.org/wiki/Guard_(computer_science) Guard block guards against special ...
3
votes
4answers
233 views

Finding largest sequence in 2D array

I'm practicing problems and found this weird one. I can't figure out the best way to solve it. You are given a 2D matrix size n*n with only 1's and 0's, you have to find the longest sequence of 1's ...
0
votes
3answers
150 views

How do you enforce rules for the members of a collection in a non-OOP way?

When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
1
vote
3answers
286 views

Is it good practice to make everything internal in C#?

In our solution we have a couple of projects, a project for data layer, service layer, business layer. etc. Inside the business layer, we use models to transfer data from classes to classes. Is it ...
0
votes
2answers
58 views

Module with globals or Class with attributes?

Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
5
votes
3answers
231 views

Word order for names [closed]

I'm working with a team of non-native English speakers and I'm struggling to come up with a rule that explains why a method should be called getFilePath and not getPathFile. Examples of this bad ...
2
votes
0answers
45 views

Managing application versions using Conan and RPM

I have a shared object that I developed. This shared object is packaged in two forms, a Conan package, and an RPM. It is a Qt project, so it has a .pro file associated with it. Up until now, we ...
6
votes
6answers
515 views

Should error codes in JSON be integers or strings?

I'm designing a backend webservice, and when an error occurs I'm returning it as a JSON to the frontend. This JSON contains an error code, which the frontend maps to an localized string and shows that ...
0
votes
1answer
127 views

Visibility of constants

Should constants of my class only be public if I know that they will be used from their users or doesn't it hurt to make all of my constants public per se? Is not exposing all constants cleaner?
1
vote
1answer
163 views

Best practices: Save or return intermediate results?

Assuming IO is not an issue, is saving intermediate results considered a best practice? What are the pros and cons, and situations that warrant doing so or not? Say I have two components along a long ...
0
votes
0answers
125 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
294 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 ...
2
votes
0answers
108 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
493 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): ...
4
votes
1answer
178 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
5k 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
57 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
264 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
82 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 ...
-5
votes
2answers
162 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
184 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
4answers
329 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
56 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
227 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
130 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
198 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
412 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
164 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
611 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
414 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 ...
2
votes
5answers
509 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
373 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
171 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
100 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
163 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
135 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
143 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
188 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 ...