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
0
votes
0answers
12 views

Should I put add() method in Laravel model

It's my first post here as I understand that SO is a platform to find fixes and this is where to ask questions about more general questions. Correct me if I'm wrong I'm working on project in Laravel ...
-3
votes
1answer
51 views

Where is it appropriate to implement the split_array method

I am writing an implementation of a binary search tree and in doing this I need a method that splits an array in two. I am unsure where it is appropriate to place this method. What I mean by "where ...
0
votes
2answers
115 views

Should we check if the primary key exists if rendering a collection fetched from database?

I have got an argument with my colleagues about this. IMO It's common practice that you don't need to check if an id exists or not before rendering it. So here's an example. This is what my ...
3
votes
1answer
245 views

Is there a UML diagram for functional programming?

For modelling software implemented with the imperative or procedural programming paradigm we have Flowcharts, process diagrams, etc. For object oriented we have UML class diagrams, object diagrams, ...
-3
votes
0answers
36 views

How to keep model/enum in sync with database

Right now I have a factory method that instantiates an object based on an enum parameter. For example: public IAnimal GetAnimal(Animal animal) { switch (animal) { case Animal.Cat: ...
0
votes
3answers
210 views

How to name functions with multiple return values

In many languages, it is common for a function to have multiple return values (as a tuple), such as: def foo(): return "Hello, World!", 0 I often do this when a computationally expensive (or an ...
0
votes
0answers
101 views

what is the best way to make one file appear in two directories

I'm trying to develop a CSS library where I style each element and it an example HTML page. However, I came across those two elements (<cite> <blockquote>) whose examples must be shared ...
-2
votes
3answers
146 views

Good practice for JavaScript (ES6) data objects

I see very often to pass around unnamed data objects in JavaScript, e.g. { a: 1, b: 2}. Is it a good practice or is better to make a simple data class for that like in other languages: class ...
0
votes
3answers
224 views

How to best handle valid but impossible input?

Say I write a function which expects the input to be A or B. The input may be C, which is technically valid but should be impossible if the logic of the rest of the program is working correctly. ...
-4
votes
1answer
50 views

Is it a good idea to use a Parser Combinator to parse unstructured input?

I'm writing a parser that needs to accept unstructured input. By that I mean it needs to take in a raw signal (text, in this case) and look for significant character sequences while accumulating the ...
9
votes
6answers
1k views

Another word for “removing code” [closed]

I'm creating a branch in source control to strip large parts of an application out. Whilst giving this branch a name, I started questioning if "removal" is the right word. As I'm not specifically ...
1
vote
4answers
153 views

Separating data and behavior in Java

I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and ...
2
votes
2answers
115 views

Should microservices in an event sourced architecture not communicate directly with one another via REST/gRPC/etc?

I'm trying to wrap my head around event sourced architectures. It seems like common advice is to have small events with as little info in them as possible (opposed to large events with everything in ...
9
votes
2answers
1k views

What is the name for the integer part of a enum?

I've been writing some code comments, and I've been trying to refer to the index integer of a enum type, but I'm not sure what it's called. I'm tempted to call it the identifier, however there is ...
-1
votes
2answers
96 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
170 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
150 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
311 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
105 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
458 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
97 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
49 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
256 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
315 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
154 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
297 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
63 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
237 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
55 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
524 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
135 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
171 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
201 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
302 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
498 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
180 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
65 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
267 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
87 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
92 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
164 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
298 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
331 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
57 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
229 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
131 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, ...