Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [coding-style]

Coding style is a set of guidelines that helps readability and understanding of the source code.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
137 views

So I was coding in C for a while now, getting used to language syntax and different styles. Implemented a couple of simple data structures, algorithms and tried my skills in making Minesweeper clone. ...
MightyBeast's user avatar
2 votes
4 answers
489 views

Threre are two functions FindMaxDistanceVector and FindMaxDistanceList whose implementation is almost same except some debug information added in FindMaxDistanceList. Note that these two functions are ...
user146290's user avatar
0 votes
2 answers
364 views

Which code style is preferred in Java? final boolean result = isCausedBy(e, ExceptionType1.class) || isCausedBy(e, ExceptionType2.class) || isCausedBy(e, ExceptionType3.class) |...
Andriy Makukha's user avatar
1 vote
3 answers
308 views

Recently, I had a debate with one of my friends on using type inference in C# (var keyword). His argument was that we should stick to using the explicit type names because "even with the ...
Zombies are Real's user avatar
2 votes
3 answers
241 views

According to https://softwareengineering.stackexchange.com/a/212130/432039, if a class asks another class for the state, and then call methods of that class, it is called "feature envy", eg: ...
wcminipgasker2023's user avatar
10 votes
4 answers
2k views

According to https://softwareengineering.stackexchange.com/a/180616/432039 suggested, I know the answer advised "auto" should be used instead of the actual type when declaring variables. ...
wcminipgasker2023's user avatar
1 vote
5 answers
253 views

Consider the two following examples: public Something fetchSomething(String key) { if(somethingsMap.containsKey(key)) { return somethingsMap.get(key); } throw new ...
steros's user avatar
  • 121
6 votes
4 answers
3k views

Uncle Bob mentions in his book "Clean Code" that "[f]unctions should do one thing [...] only" and advocates that a method should stick to one abstraction level (I'd call it flight ...
Christian's user avatar
  • 171
14 votes
5 answers
5k views

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
0 votes
4 answers
436 views

I've been wondering about code expressiveness vs. conciseness lately. What I mean by that is that a lot of modern programming languages offer features to express statements in a very short manner, ...
Sir Falk's user avatar
1 vote
2 answers
355 views

I'm writing a C++ class, CBookSpellDef which has the following methods: int GetIndexOf(const char *psz); char* GetNameAtIndex(int index) { return m_spellTypes[index].szName; } char* ...
Bunabyte's user avatar
  • 643
24 votes
11 answers
8k views

Our codebase has a typical base-class with a ton of sub-classes. The base-class already has many default functions for the sub-classes. However, one particular function has the same verbatim ...
Zack Light's user avatar
0 votes
1 answer
278 views

I recently changed my job to a big MNC and the code I am exposed to is highly complicated, difficult to read and understand. Although it is divided in microservices and runs on local I have to keep ...
Surya Saini's user avatar
17 votes
8 answers
7k views

I'm a Software Engineer who sometimes need to review the code of my fellow team members. I often look at the source code and think; this looks fine. I'm having a hard time to think critical about it. ...
Jay's user avatar
  • 289
-2 votes
3 answers
1k views

There's a lot of free or member predicate-like functions (that returns boolean value) in different programming languages and popular libraries/frameworks that have "is" as a prefix, e.g.: ...
αλεχολυτ's user avatar
2 votes
2 answers
633 views

Generally print statements are frowned upon in favor to logging. But are there any situations where I should prefer using print statements? In a interactive command line application, if I ask for user ...
Sourav Kannantha B's user avatar
13 votes
3 answers
3k views

I'm writing a validator class to validate certain request objects against a known format. Rule declarations and the validator will both be written entirely in Python, and I don't need to store the ...
JSBձոգչ's user avatar
  • 1,440
0 votes
0 answers
59 views

Our coding standards for C include various prefixes for data types, constants, static/global variables, and pointers. These prefixes were originally introduced for code review purposes, but with the ...
Cem Polat's user avatar
  • 127
2 votes
1 answer
279 views

In a Java open source project built with Maven, is there a standard way to declare code style settings (such as indentation settings and import order)? I would like that people who import the project ...
pintoch's user avatar
  • 159
21 votes
4 answers
10k views

I have a situation like the following: int fds[2]; pipe(fds); // Write lots of stuff into fds[1] close(fds[1]); do_stuff(fds[0]); // Should I close fds[0] here or at the end of do_stuff? Which one ...
eem's user avatar
  • 329
0 votes
1 answer
151 views

In my new job, I'm getting a hard time understanding how they want to model things... they are using Domain Driven Design. For example, I come across this kind of code: $userRepo = new UserRepository($...
JorgeeFG's user avatar
  • 697
0 votes
4 answers
439 views

According to Should interface names begin with an "I" prefix?, I should not add prefix "I" to interfaces. However, I think prefix "I" in interface may be useful sometimes....
wcminipgasker2023's user avatar
24 votes
6 answers
9k views

What is considered better practice? Case 1: if n == 0: doThis() elif n < 0: doThat() elif n > 0: doSomethingElse() Case 2: if n == 0: doThis() elif n < 0: doThat() else: ...
Nikhil Kumar's user avatar
0 votes
2 answers
217 views

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
wcminipgasker2023's user avatar
5 votes
4 answers
3k views

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know I should avoid get the state of an object and then decides the actions to take to that object, eg: Bad: ...
wcminipgasker2023's user avatar
2 votes
3 answers
356 views

I know there are some posts talk about primitive obsession : When is primitive obsession not a code smell?, Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession&...
wcminipgasker2023's user avatar
18 votes
6 answers
5k views

According to When is a number a magic number?, I know magic number should not exists, so I know the following code about creating a Label from some UI framework and set the color RGB needs to be ...
wcminipgasker2023's user avatar
1 vote
1 answer
216 views

Suppose I need to find the last selected index of options according to last selected contents, eg: options : A,B,C,D,E ,last selected option: C, so the last selected index is 2. There is a special ...
wcminipgasker2023's user avatar
6 votes
7 answers
7k views

For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int ...
wcminipgasker2023's user avatar
0 votes
1 answer
88 views

This question may get closed quickly, but I'll appreciate any advice I can get and all the resources I can find online about this topic aren't quite relevant to my case. I am a Math PhD student doing ...
msm's user avatar
  • 109
1 vote
3 answers
642 views

For example, I know in c++, I can use myString=="abc" to check if 2 strings are equal. However, in Java, it is comparing if 2 objects are the same object. Also in other language, for ...
wcminipgasker2023's user avatar
4 votes
1 answer
340 views

I am working with a library that is somewhat poorly written. In order to function, it requires several global variables to be declared and sometimes even maintained by my own code. I really don't ...
Infinite_Maelstrom's user avatar
1 vote
3 answers
314 views

We're trying to update our style guide (using google's guide as a starting point) and I'm currently in the middle of a debate with my colleagues about column limits. I believe we're all in agreement ...
Zachary Coffin's user avatar
1 vote
1 answer
307 views

A module app.js includes another module service.js. The service.js module/file contains some functions but also does some module scoped initialisations(registry variable). // service.js const ...
Cap Barracudas's user avatar
0 votes
2 answers
179 views

I am not a native english speaker so I have the following question related to naming I have a class that has generic filter method of type: filter(Predicate predicate) In the same class I have some ...
Alexander Petrov's user avatar
0 votes
4 answers
222 views

I have the existing code provided below: if (!$existing_records && !$has_required_field) { return 'Skip Update, no records found'; } elseif (!$existing_records && $...
Muhammad Dyas Yaskur's user avatar
17 votes
6 answers
7k views

A common scenario I have is this: I download a new codebase. In order to have me understand the code, I need to litter it with my own comments about what each section of code does. It seems ...
user3180's user avatar
  • 283
15 votes
6 answers
6k views

This is just a simple code-style question. Imagine you're writing a function in language 1 that is supposed to be called from language 2. Should the function follow language 1's style guidelines or ...
Fluffyalien's user avatar
10 votes
8 answers
2k views

I just finished a discussion with colleagues regarding the use of exceptions in code. Here is the code (pseudocode) that they had written: resp = fetch(URL) if resp.status_code != 200: return ...
Daniel's user avatar
  • 527
1 vote
1 answer
161 views

Context After creating a (bash) CLI interface that creates self-signed SSL certificates (for onion domains), the user can choose to re-use some of the data that is created in past runs. For example, a ...
a.t.'s user avatar
  • 225
0 votes
2 answers
179 views

Given the following hierarchy of objects: a keyed collection of ClassA objects, where each ClassA object contains a keyed collection of ClassB objects and each ClassB object contains a keyed ...
PieterV's user avatar
  • 233
-1 votes
1 answer
217 views

I was going through an old, largely untouched part in my company’s codebase and found one API. It does the following things. A POST API with path host/entities/trigger which fetches a list of entity ...
elliot's user avatar
  • 11
40 votes
6 answers
14k views

We've been utilizing pair programming (or something like it) for a few years. As a senior engineer on the team - I find that pairing actually negatively impacts the team's throughput. The common ...
antonpug's user avatar
  • 571
0 votes
2 answers
722 views

I recently took on a long ago python project which has some weird code style that I can't pinpoint. e.g. # this is a params and value package? opts={ infile="xxx", outfile="xxx" } ...
zhang's user avatar
  • 111
2 votes
1 answer
672 views

I found the short article Align the happy path to the left edge quite helpful in improving readability of functions. Briefly, reading down the left edge of the function should step you through the ...
lofidevops's user avatar
8 votes
4 answers
2k views

Java is often (rightly IMHO criticized) for overusing the class keyword, as it can denote: a factory to instantiate objects (traditional classes) a collection of global methods (when all methods are ...
Ray Toal's user avatar
  • 1,325
3 votes
0 answers
170 views

Let's say my language's standard library does not include TrickyFunction(). Since implementation seems quite trivial for me, I decide to create utils in the project and add such function, for others ...
JoshThunar's user avatar
4 votes
5 answers
1k views

Why would so many repositories use additional — apparently unnecessary — vertical and horizontal space in coding styles? I almost unanimously see this: public function getName() { ...
Nobody-Knows-I-am-a-Dog's user avatar
0 votes
2 answers
405 views

I have thought of this for a while and I want to know what you think about this. This is more of a way to structure the code that might not be 100% object oriented and that is not the purpose. I would ...
Cowborg's user avatar
  • 109
2 votes
2 answers
262 views

I have an intuition, that I'd like to read what others have talked about. To me, it seems fairly intuitive that when you have a function which is called multiple times with the same arguments, it ...
Thiago Pereira Maia's user avatar

1
2 3 4 5
22