Skip to main content

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
17 votes
8 answers
5k views

When should a function be given an argument vs getting the data itself?

When is it better to pass data to a function in a parameter, and when is it better for the function to just fetch the data itself? Here's some simplified examples in PowerShell: Option 1 (give the ...
Nova's user avatar
  • 181
3 votes
2 answers
381 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 ...
J. Mini's user avatar
  • 1,017
3 votes
7 answers
419 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 ...
J. Mini's user avatar
  • 1,017
1 vote
2 answers
573 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(...
Scarabee's user avatar
  • 121
2 votes
0 answers
99 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 ...
J. Mini's user avatar
  • 1,017
0 votes
3 answers
1k 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 ...
Cave Johnson's user avatar
0 votes
1 answer
167 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 ...
Ignorant's user avatar
  • 357
38 votes
10 answers
10k 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 ...
J. Mini's user avatar
  • 1,017
-2 votes
1 answer
2k 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 ...
Joe C's user avatar
  • 115
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 ...
George Z.'s user avatar
  • 705
4 votes
2 answers
1k 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 ...
cidra's user avatar
  • 343
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 ...
George Z.'s user avatar
  • 705
0 votes
1 answer
130 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 ...
hardhypochondria's user avatar
2 votes
4 answers
817 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....
Kevin's user avatar
  • 374
1 vote
2 answers
164 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 ...
George Z.'s user avatar
  • 705
4 votes
4 answers
158 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 ...
George Z.'s user avatar
  • 705
0 votes
3 answers
253 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 ...
Vencovsky's user avatar
  • 371
2 votes
3 answers
2k 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 ...
Vencovsky's user avatar
  • 371
1 vote
1 answer
160 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 ...
GoldFlsh's user avatar
  • 147
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 ...
pstatix's user avatar
  • 1,047
5 votes
4 answers
372 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 ...
ibi0tux's user avatar
  • 241
4 votes
1 answer
191 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 ...
weno's user avatar
  • 281
8 votes
5 answers
665 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'...
weno's user avatar
  • 281
-1 votes
5 answers
2k 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-...
J. Mini's user avatar
  • 1,017
0 votes
1 answer
143 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 ...
The Gilbert Arenas Dagger's user avatar
0 votes
5 answers
246 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 = "...
john c. j.'s user avatar
78 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(&...
Heinzi's user avatar
  • 9,798
-2 votes
2 answers
261 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 <...
Robin's user avatar
  • 107
0 votes
1 answer
151 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 ...
ibi0tux's user avatar
  • 241
3 votes
2 answers
4k 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 ...
mushishi's user avatar
2 votes
5 answers
513 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 ...
user7681202's user avatar
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 ...
Jimbotron's user avatar
5 votes
4 answers
230 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 ...
foo's user avatar
  • 169
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 ...
john c. j.'s user avatar
-1 votes
1 answer
46 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, ...
xana's user avatar
  • 117
-4 votes
1 answer
368 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 ...
Jesús Díaz Castro's user avatar
8 votes
5 answers
938 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 ...
Nae's user avatar
  • 197
0 votes
4 answers
95 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 ...
Mahkoe's user avatar
  • 119
0 votes
1 answer
85 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 ...
user949300's user avatar
  • 8,889
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? ...
Sandra Gilbert's user avatar
0 votes
1 answer
253 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 ...
gabriel.hayes's user avatar
3 votes
3 answers
648 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 ...
John Wu's user avatar
  • 26.6k
-2 votes
1 answer
224 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 ...
Sisir's user avatar
  • 858
2 votes
1 answer
365 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 ...
Fabio Filippi's user avatar
1 vote
3 answers
480 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": ...
john c. j.'s user avatar
1 vote
5 answers
367 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 ...
Daniel Smith's user avatar
2 votes
2 answers
212 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
511 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 ...
Ana Nimbus's user avatar
2 votes
2 answers
775 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),...
TheJeff's user avatar
  • 139
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 ...
john c. j.'s user avatar

1
2 3 4 5
11