Questions tagged [language-agnostic]
This tag is for questions that aren't specific to a programming language or environment.
549
questions
3
votes
2
answers
339
views
When refactoring many functions that share state in to a single class, how can you avoid writing an "escort" class?
This well-known article criticises Java on the basis that it does not allow you to write functions that do not live in a class. This flaw forces you to write classes with names that look suspiciously ...
3
votes
7
answers
344
views
How can unit tests be atomic in server-dependent CRUD apps?
Suppose that the following are true:
You believe that unit tests should be atomic. That is, tests should always test exactly one thing.
You have written a CRUD app in a general-purpose language such ...
1
vote
2
answers
327
views
Ordering keyword arguments in a function call
In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it?
For instance, suppose that a function's signature is def foo(...
2
votes
0
answers
95
views
Should the usage of an needlessly mutable type by pointed out in code reviews, even when multi-threading is not a concern? [closed]
None of my team's programs care about multithreading, parallelisation, async, or anything else that benefit from immutability. However, immutability is clearly in fashion at the moment and I'm ...
0
votes
3
answers
815
views
Is it code smell to make an abstract child class override a parent method which only calls its own abstract method
Is it code smell to make an abstract child class implement a method, which overrides a parent method, whose only purpose is to call another abstract method? I want to make sure that anyone who ...
0
votes
1
answer
160
views
Does a monolithic "main" class make sense?
I'm working on an application that contains a central class, called Engine, made of different sub-modules (classes), where each module is responsible for a specific functionality. Those modules are ...
38
votes
10
answers
9k
views
Why do heavily object-oriented languages avoid having functions as a primitive type?
As has been covered to the point of parody, heavily object-oriented languages, such as C# or Java, tend to lack the feature of having functions as a primitive type. You can argue about whether or not ...
-2
votes
1
answer
982
views
What difference is there, if any, between a KPI and an SLI? [closed]
We are revisiting how we do observability at my organisation, and I'm reading about Service Level Indicators (SLIs) as a way of measuring how our systems are performing. But what I'm struggling to ...
31
votes
9
answers
7k
views
Is extracting an interface just for testing purposes a code smell?
I will explain with an hypothetical example.
Suppose that my domain is Cars. Everyone around the software, talks about cars. Car is the aggregate root of aggregate roots. For example, CAR table has ...
4
votes
2
answers
746
views
When modeling requirements, how can I depict class diagram attributes whose allowed values are custom defined and in finite number?
I'm drawing the class diagram that depicts the domain model of a system. This diagram is for requirements analysis purposes so it is completely implementation-agnostic.
I want to communicate the ...
9
votes
5
answers
1k
views
Today I wrote "tests" for the testing code. Was it the right thing? Is it a smell?
My application has big integration with the database. Classes that use the database are very crucial for the system, so I write small unit tests for classes that I call Repository. The reason behind ...
0
votes
1
answer
98
views
Decoupling data validation from data processing
I'm trying to implement a web service API client using the guidlines i've found in this article:
https://www.oreilly.com/library/view/designing-evolvable-web/9781449337919/ch09.html
As it comes to my ...
2
votes
4
answers
693
views
Using a switch statement in place of multiple ORs in an if statement
I was doing a code review today and came across a change that, while it works, "smells" to me.
Original code:
if(itemStatus.equals(ItemStatus.Preparing)){
orderStatus = OrderStatus....
1
vote
2
answers
130
views
Should selected person be part of my application layer? (MVP pattern)
Consider the following GUI screen:
When user selects a person from PersonListView, EditPersonView should show person's first name and last name and allow the user edit. So, I end up with the ...
4
votes
4
answers
145
views
Approach to keep collection of parent entity sorted when child changes?
Assume a Person has a Phone and a Phone has Contacts. Assume in the real world the Contacts of a Phone are sorted by their first name.
When I phone.add(Contact c), the phone sorts its contacts. Then ...
0
votes
3
answers
191
views
How to create a code that will be send by SMS to verify that it's a valid phone number? [closed]
I'm creating a mobile app that will have a verification process of the phone number like most of apps do when they use your phone.
I'm also developing the back-end but I don't know exactly what is the ...
1
vote
3
answers
1k
views
Should I keep in the database a record of the user accepting the terms and coditions?
Most of applications, when you sign up, you must agree with some terms and conditions.
Should the information that the user agreed to those terms be saved in the database?
I asking this because I'm ...
1
vote
1
answer
122
views
Code reference symbols in documentation, comments and pull requests?
I've seen method references in PRs and comments and documentation but it's unclear what the specific symbology means.
E.g. ClassName#myMethod or ClassName::myMethod or what about ClassName::CONSTANT
...
3
votes
3
answers
2k
views
Define "constants" at the global or function scope?
I often define variables that will never change, i.e. constants, at the top of a script/module. But recently I've been wondering if it makes sense to define them at the function scope level if they ...
5
votes
4
answers
365
views
How to deal with different level of abstractions (blurred line between data and models)
My question is about the way to represent data models created at runtime.
To illustrate, let's say we would like to create a CMS-like app in which end-users may create custom forms.
Those forms are ...
4
votes
1
answer
179
views
Accessing Animal not belonging to User: 400, 401, 403, 404, other?
Consider animals being some REST resources. User has animals assigned to him.
The endpoint /api/animals/{animalId}/feed is used to feed a given animal by the authenticated user.
User should not be ...
8
votes
5
answers
622
views
How to avoid making User a god object?
Consider typical gym trainings tracker app.
User has account related attributes:
User {
id
login
password
email
fname, lname
isBlocked
}
However, the requirements are that an application'...
-1
votes
5
answers
1k
views
Why is converting 0-indexed code to 1-indexed code non-trivial?
The disadvantages of 1-indexing are well-known. However, our hand is sometimes forced by our choice of language and we have to convert algorithms that were intended for a 0-indexed language to being 1-...
0
votes
1
answer
126
views
Refactoring powershell codebase to support multiple environments
I come from a Java background, but now I'm supporting a PowerShell code base. In the PowerShell code base there are multiple modules that were written against a certain Azure environment. Now, we ...
0
votes
5
answers
243
views
The cases where returning Bools as literal expressions is a better option
Most people would return Bools as follows:
bananas(color) {
return (color = "yellow")
}
and not as literal expressions; that is, not this way:
bananas(color) {
if (color = "...
77
votes
7
answers
6k
views
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
Many high-level programming languages have built-in features to format a number with a system-dependent currency symbol:
-- Outputs $100.00 (en-US) or € 100,00 (de-AT)
Console.WriteLine(100.ToString(&...
-2
votes
2
answers
250
views
Is looping an array to compare to itself considered O(n^2)? [duplicate]
Often when I'm doing an operation comparing an array to itself, I write code along these lines:
function operation (array) {
for (let i = 0; i < array.length; i++) {
for (let j = i + 1; j <...
0
votes
1
answer
147
views
How to deal with metaclasses in strong-typed language : is it ok to mix classes and metaclasses?
I'm working on a programming language design ans I'm struggling with how I should type the concept of Class.
Let me show you some code to illustrate my problem :
class MyClass
{
}
function ...
3
votes
2
answers
3k
views
Programming a library in multiple languages
I am planning to implement a cryptographic library for several languages and looking for best practices. I have looked at several threads, especially this, this, and this one, which answer my ...
2
votes
5
answers
503
views
Why OOP languages use the syntax "object.function()" to send a message?
In C++ and Java and many other OOP languages, in order to send a message to an object, you have to use the object.function() syntax, for example:
myCar.start(); // send the start() message to the ...
5
votes
5
answers
1k
views
How can billion integer ids be stored and specific ones checked for existence most efficiently? (persistent solution, not just in-memory)
Let me preface this by saying that I am familiar with RDBMS. I have a solution using mysql/mariadb but I am not happy with the efficiency of the solution so I'm looking for alternatives.
I'm trying ...
5
votes
4
answers
229
views
How to describe a function argument that is used as a hint/best-effort?
Say I have a server exposing an api that let me retrieve 'things', there are a lot of things, and as such retrieving all things at once could take down the server, hence the exposed API returns ...
8
votes
9
answers
9k
views
Returning true/nothing instead of true/false?
Is it OK to have a function that returns true/nothing instead of true/false?
My examples use JavaScript, but I'm wondering about the general case, not attached to one specific language.
The subjects ...
-1
votes
1
answer
44
views
How to check whether module or class is network interface, socket?
Background
Simplifying, assume I want to write some tool for code-analysis, which tell me which files - class/module - are/have some kind of network interface(s). No matter if it's REST Controller, ...
-4
votes
1
answer
253
views
Does it makes sense to implement a REST API for every app?
Is it mandatory to implement a REST API even if it doesn't make sense?
I have created an app consuming REST services from other apps. Now that I have the final result, I wonder if it is needed to ...
8
votes
5
answers
904
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
...
0
votes
4
answers
89
views
When to use known languages/libraries vs. investing in learning new ones?
This question is asked in a general way. In case it is hard to understand, I have added a concrete example below. I am interested in the answer to the general question.
I have a lot of experience ...
0
votes
1
answer
82
views
Organizing Parallel Arrays of Promises / Async tasks
I'm struggling a bit for a preferred way to organize a sequence of asynchronous tasks that can be applied in parallel. Say, you are parsing data from many files. In my case I'm using javascript and ...
9
votes
8
answers
2k
views
Should a function throw exceptions based on its expected behavior or its goal state?
My coworker and I are debating the correct design for an API. Say we have a function void deleteBlogPost(int postId). What should this function do if the blog post indexed with postId does not exist?
...
0
votes
1
answer
195
views
What Actually Indicates the end of a Socket Input/Output feed?
In the most abstract, platform agnostic way possible, can someone explain what actually determines the end of input/output a socket? Is this something the programming language itself typically handles ...
3
votes
3
answers
522
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 ...
-2
votes
1
answer
196
views
Are all sockets implemented as per the Berkeley sockets specification?
Are all sockets implemented as per the Berkeley sockets specification in all platforms or languages? What I am trying to understand is; is this the only standard for sockets implementation or there ...
2
votes
1
answer
296
views
Parallel execution: 1 thread pool or N thread pools?
I have a tree generated by configuration.
Each leaf of the tree is a long running task (like DB query, reading from file, etc.) that gives a result I want to store in a mirrored tree with only the ...
1
vote
3
answers
432
views
Are 'array elements' and 'array values' the same?
Array := {"title": "Book Title", "author": "John Doe"}
Some people use the following terminology:
title and author are keys.
Book Title and John Doe are values.
"title": "Book Title" and "author": ...
1
vote
5
answers
361
views
When do I stop being paranoid about my code failing? [closed]
I'm currently designing a system that, no matter how hard I try to break, slow network, failures, random server deaths, it can recover and it can re-build again. Each action it does is a fragment and ...
2
votes
2
answers
197
views
Is there a guideline as to when I should pass a collection as an argument or return a new collection?
Suppose I have the following methods:
def read(file: str) -> List[str]:
temp = []
with open(file) as f_obj:
for line in f_obj:
temp.append(line)
return temp
def ...
1
vote
1
answer
434
views
What is the BNF (or BNF-like) syntax for a specific number of repetitions?
I would like to write something like
<byte> ::= <bit>*8
to mean that a <byte> is a sequence of exactly 8 <bit>'s.
Is there a way to do this in BNF[1][2] or a widely used ...
2
votes
2
answers
659
views
Localize a countdown timer
I have a very specific localization problem that I have not had any luck finding specific information about in my research.
I have an app that I'm localizing that shows elapsed minutes(M), seconds(S),...
0
votes
2
answers
108
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 ...
0
votes
3
answers
492
views
Do higher order functions violate the separation of data and code principle?
I am asking here something that is really haunting for years (for real !).
I guess in a "perfect world", we would have programs made of data models and functions, and those functions manipulate data ...