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
-4 votes
1 answer
74 views

Question about the tutorial purgatory in coding path

Dear all the programmers and overflow friend, First, I want to say thank you to stack overflow users for helping me finish 20% of my PhD project since last year (using python to draw some technical ...
1 vote
3 answers
129 views

Good etiquette for 2 optional arguments that can't both be used

I'll demonstrate with an example of the normal distribution in Python. def norm_pdf(x, mu=0, v=1, p=1): """Returns un-normalized probability density of normal distribution at x. mu: mean v: ...
  • 165
8 votes
5 answers
845 views

Is it bad practice to add "false or" or "true and" to conditionals?

Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
  • 197
-4 votes
2 answers
136 views

How to exploit efficiency of C? [closed]

I want to write a program that performs heavy computations and I want it to be as fast as possible, so I choose C to be the language. Nevertheless, I was told that in spite of its simplicity and high ...
-1 votes
2 answers
189 views

Explaining why a code's modifier should also be its committer [closed]

The context of this question is the early stage of introducing a VCS into an academic setting consisting of non-SW-engineers, largely unaware of modern best practices related to coding as a team. At ...
  • 233
0 votes
2 answers
88 views

How sensible is it to build a website/app etc. using an external api?

Wanting to expand my programming horizons I recently started building a website. I have started to build up my website and it is heavily focused around an external api. The reason for using this api ...
1 vote
1 answer
83 views

Using Builtin Method vs Manual Implementation

I work in a DevOps role and mainly write glue code and OS-level automation. I've rarely needed to deviate from existing language implementations or "reinvent the wheel" in the small programs I've ...
-3 votes
1 answer
309 views

What are the best practices for writing a long, multi-step process? [closed]

When writing a long process, i.e. one filled with many steps of business logic, what are the best practices for organising it? There are a few different options here that I can see: Just write a long ...
-4 votes
3 answers
116 views

What can an assertion test that running the actual code cannot?

I'm currently learning Jest, Enzyme, Detox and testing in general, but I'm still trying to grasp the benefit of testing. From what I understand, testing is about creating hypothetical situations. Let'...
user avatar
10 votes
3 answers
1k views

Is porting code from different language plagiarism?

Is porting code from one programming language to another considered as plagiarism?
0 votes
2 answers
867 views

Should I use a class with only static members to encapsulate my program?

So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
3 votes
5 answers
431 views

Always better to wait?

I've been wondering if this concept has a name and a consolidated theory behind. If you need to build software, but you don't need it right now, it's always better to wait because the technology ...
  • 155
2 votes
2 answers
272 views

The usage of getter notation inside the context of the class

Consider the following JavaScript code: class MyClass { #myPrivateField; constructor() { #myPrivateField = new AnotherClass(); this.theGetter.method1(); // or: this.#myPrivateField....
  • 129
-4 votes
1 answer
125 views

Choosing the correct "opensource" license for codes [closed]

In programming terms, what defines Open Source? I am building a platform that I want to be open, to be used by other programmers in the context of running their own apps on it at the same time for ...
  • 127
2 votes
1 answer
114 views

Is it a good software engineering practice to store libraries as attributes of objects?

Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...
1 vote
1 answer
176 views

Alternatives to service locator with opaque pointer in C

I have a project in which one module keeps the state of the target device (things like current command level, but mostly status registers caches). I'm aware that having a global public variable (...
  • 605
28 votes
9 answers
8k views

In software design, should an application remain agnostic regarding its usage with real world data / mock data?

Let me try to summarize a bit more with a simple example: You're building a large application, a user portal for example, with feeds, news, account management, and a whole range of difference ...
  • 405
0 votes
1 answer
138 views

Is it considered a good practice to hardcode package versions in something as high-level as a Dockerfile?

We had an application break in production during a deployment because a load-balancer package in our top-level Dockerfile had pulled its latest version, which happened to have a new API. Our app broke ...
3 votes
3 answers
392 views

Why is it better to use parameters instead of temporary global variables?

If you're a very old programmer like me you may have written stuff like this early on: DIM A, B, C LET A = 2 LET B = 2 GOSUB ADD PRINT C END ADD: LET C = A + B RETURN (Actually, if you're an ...
  • 25.1k
10 votes
2 answers
1k views

What form of verb to use (imperative verb or third-person verb) in programming?

Here are a few examples: Imperative verb Initialize! InitializeWhenCreated! RequireValue! Third-person verb HasValue? RequiresValue? Are there some rules how to choose either imperative verb or ...
  • 267
2 votes
1 answer
466 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 ...
-1 votes
1 answer
64 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
2 answers
132 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 ...
6 votes
1 answer
3k 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, ...
  • 97
2 votes
3 answers
2k 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
3 answers
212 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 on an example HTML page. However, I came across those two elements (<cite> <blockquote>) whose examples must be shared with ...
1 vote
3 answers
4k 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 ...
  • 176
0 votes
3 answers
275 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. ...
  • 111
-4 votes
1 answer
248 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 ...
11 votes
6 answers
2k 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 ...
  • 329
2 votes
4 answers
1k 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 ...
4 votes
2 answers
331 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 ...
  • 301
9 votes
2 answers
2k 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 ...
  • 575
-1 votes
2 answers
219 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
3 answers
581 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
2 answers
402 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. ...
  • 9
1 vote
2 answers
520 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
1 answer
779 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 ...
  • 17
-3 votes
2 answers
209 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 ...
2 votes
4 answers
2k views

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

Recently I was going through some of the source-codes of the best competitive programmers in the world. I found out that those people use a template while writing programs, preferably in C++. I have ...
0 votes
2 answers
107 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
1 answer
150 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
1 answer
271 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
4 answers
882 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
3 answers
164 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 ...
  • 641
4 votes
3 answers
2k 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 ...
  • 292
0 votes
2 answers
706 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 ...
  • 111
6 votes
3 answers
301 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
0 answers
153 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 ...
7 votes
6 answers
2k 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 ...
  • 223

1 2
3
4 5
32