Questions tagged [language-agnostic]
This tag is for questions that aren't specific to a programming language or environment.
541
questions
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 ...
3
votes
2
answers
110
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
737
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
51
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
390
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
73
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
136
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
85
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
215
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 ...
0
votes
1
answer
91
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
...
2
votes
3
answers
323
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
329
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
167
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
485
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'...
0
votes
5
answers
674
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
66
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
234
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
233
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
126
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
1k
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 ...
1
vote
5
answers
441
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
603
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
222
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
6k
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
33
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
117
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
829
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
86
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
79
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
734
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
91
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
363
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
149
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
185
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
300
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
350
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
187
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
241
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
454
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
106
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
375
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 ...
10
votes
5
answers
607
views
If-else ladder that is supposed to catch all conditions - should a redundant final clause be added?
This is a thing I'm doing a lot lately.
Example:
setCircle(circle, i, { current }) {
if (i == current) {
circle.src = 'images/25CE.svg'
circle.alt = 'Now picking'
} else if (...
2
votes
1
answer
269
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
1
answer
301
views
How to make updates to data and return list of updates without breaking Command query separation or DRY?
I have a use case to make updates to a slightly complex JSON object and then return the list of changes made (not the updated data). The process of finding the list of changes is extremely similar to ...
3
votes
5
answers
800
views
Should exceptions be only thrown if I intend to crash the program? [duplicate]
...I wanted to find the source before writing this Q, sadly I couldn't.
My mental model was that exceptions were thought as an alternative to returning error codes from a function, which is the C ...
1
vote
1
answer
173
views
Bin packing with "flexible" items: Does this algorithmic problem have a name? [closed]
I have stumbled upon the following problem: I have one list of containers with "capacities", and a list of items with quantities. I want to assign those items to the containers. The total capacity of ...
2
votes
1
answer
351
views
Does it violate GRASP if a Character class checks if it can carry a weapon?
Before I ask my question, I'm aware of Eric Lippert's Wizard and Warrior series.
I'm trying to understand GRASP, but I'm having a hard time determining if this class violates GRASP.
Suppose if I ...
5
votes
3
answers
512
views
Is using exceptions to validate parameters a violation of using exceptions for control flow?
I was reading on SO and SESE about exceptions and control flow, but I can't seem to determine or figure out if using exceptions to validate parameters is a violation of that guideline.
Suppose I had ...
10
votes
2
answers
981
views
How could thread safety be provided by a programming language similar to the way memory safety is provided by Java and C#?
Java and C# provide memory safety by checking array bounds and pointer dereferences.
What mechanisms could be implemented into a programming language to prevent the possibility of race conditions and ...