Questions tagged [language-agnostic]

This tag is for questions that aren't specific to a programming language or environment.

Filter by
Sorted by
Tagged with
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 ...
user avatar
  • 695
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 ...
user avatar
  • 300
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 ...
user avatar
  • 695
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 ...
user avatar
  • 103
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....
user avatar
  • 374
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 ...
user avatar
  • 695
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 ...
user avatar
  • 695
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 ...
user avatar
  • 329
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 ...
user avatar
  • 329
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 ...
user avatar
  • 137
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 ...
user avatar
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 ...
user avatar
  • 241
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 ...
user avatar
  • 241
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'...
user avatar
  • 241
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-...
user avatar
  • 151
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 ...
user avatar
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 = "...
user avatar
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(&...
user avatar
  • 9,210
-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 <...
user avatar
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 ...
user avatar
  • 241
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 169
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 ...
user avatar
-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, ...
user avatar
  • 117
-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 ...
user avatar
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 ...
user avatar
  • 197
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 ...
user avatar
  • 119
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 ...
user avatar
  • 8,091
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? ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 24.6k
-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 ...
user avatar
  • 778
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 ...
user avatar
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": ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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),...
user avatar
  • 139
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 ...
user avatar
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 ...
user avatar
  • 241
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 (...
user avatar
  • 3,307
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 3,307
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 ...
user avatar
  • 9,210
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 2,613

1
2 3 4 5
11