Skip to main content

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
4 votes
4 answers
1k views

As a university student who just have been learning programming for a year. After I learned about the concept of state machine and the pure function in functional programming, I suddenly got an idea ...
Equescript's user avatar
0 votes
2 answers
1k views

On Stack Overflow I frequently see questions with code in the following style: function funcName(parameter) { let variable = parameter; // rest of function uses variable rather than parameter } ...
Barmar's user avatar
  • 346
-1 votes
2 answers
158 views

Let’s say that we want to encode recipes or dishes for x days in the form of a string. There can be an arbitrary number of days. Each day, we can have 0–3 of the following: breakfast, lunch, dinner. ...
hb20007's user avatar
  • 109
36 votes
11 answers
9k views

When reviewing code, I sometimes see blocks like this (I happen to be using a JavaScript since it is widely understood): if (!myVar || myVar === null || myVar === undefined) { ... } Those who know ...
Matthew Souther's user avatar
12 votes
5 answers
7k views

In many cases I can formulate some boolean parameter equally well positively as negatively, e.g. isOn or isOff. Which one should I pick then, in case I want the argument to have a default value? Is ...
DaveFar's user avatar
  • 1,466
4 votes
5 answers
2k views

I have some code on Arduino (so, written in C++) that receives a String through the UART terminal, reads the String, then decides what String to print back and how many things to print depending on ...
HFOrangefish's user avatar
0 votes
1 answer
120 views

Title sucks, I know, but I'm having trouble describing my question. Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each ...
Ryan Folks's user avatar
1 vote
5 answers
167 views

Let's say some method of a parent class is reimplemented in a child class. This child method is intended to do the same that the parent method, with a minor change. In this case, in the documentation ...
NonoG's user avatar
  • 21
0 votes
2 answers
1k views

Basic question: I am wondering if there are any industry practices or style guides that mention which of these two styles is better: if x == 0 //or nullptr or if !x (I am thinking of programming ...
JobHunter69's user avatar
0 votes
2 answers
807 views

I am implementing if/else statement, by using function "inCase" to make it more readable: const size = 'small' const equals = str1 => str2 => str2 === str1 const inCase = (obj) => ...
Djordje Vuckovic's user avatar
12 votes
4 answers
7k views

I've seen that with the Dictionary API now has methods with bool TryGetValue<TKey, TValue>(TKey key, out TValue value) and I like this kind of methods because they're signaling to the other devs ...
MaxouMask's user avatar
  • 360
-2 votes
2 answers
192 views

Assume I have a request: app.post('/order', ()=>{ // task 1 // task 2 // task 3 }) and task1 and task2 is completed but task3 failed. for example a user paid order successfully but saving order ...
Ali Shefaee's user avatar
-1 votes
1 answer
3k views

So a lot of the time my utils end up with a structure that mirrors the core library. I might end up writing a multiline version of str.center, an itertools-y function that returns the first or last ...
Jesse's user avatar
  • 111
14 votes
3 answers
3k views

When writing unit tests, I feel that there is a trade-off between code repetition and test logic. Example of my current (likely flawed) approach: To test this function (overly simple function for ...
Jasper Braun's user avatar
8 votes
3 answers
14k views

I am a junior iOS developer and here at work I find huge files with sometimes over 10,000 lines of code. Is it a good practice to put this many lines in a single file? Or is it too much. Is there any ...
Noob_iOS_Dev's user avatar
0 votes
1 answer
308 views

This question is mainly about readability and understanding of the code. Im am also in the process of creating a SCSS framework like Compass and Bourbon. I struggle to write SCSS because I like to see ...
Pagel's user avatar
  • 11
-1 votes
3 answers
273 views

How could I improve my coding skills aka skills in coding while being in a job? My job is mainly coding and so, my coding should be better and better over time. But the struggle is: There are always ...
Ben's user avatar
  • 117
0 votes
1 answer
351 views

I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually ...
Nae's user avatar
  • 197
2 votes
1 answer
2k views

What are the best practices when using global variables? Normally, the common answer to this is to avoid using global variables and use local variables, properties and arguments to pass data around. ...
Chris's user avatar
  • 535
1 vote
0 answers
93 views

Due to circumstances I'm now working in a small software company. We make e-mail marketing management software and serve some big customers as our national railways and a big bank. The software has ...
JHBonarius's user avatar
2 votes
3 answers
2k views

As an example imagine I generate a UUID/GUID for an ID in a json file. { "25d01302-2558-4c44-bf9d-385b1cc51377": ["somevalues"] } is it ok or generally frowned upon to do ...
RyanCosans's user avatar
4 votes
1 answer
2k views

In a project I have the same imports in multiple files. For example: import os import logging import json import time import pathlib and pylint will tell me I have duplicate code. I know that there ...
Chris Z's user avatar
  • 159
6 votes
5 answers
8k views

I'm working in a large company and am doing my first Java project here. We have certain code style guidelines. In the Java guideline, it is said that "assertions are only intended for debugging ...
Green 绿色's user avatar
9 votes
2 answers
1k views

If you wish to perform the same action using different parameters, you can either make differently named functions: public Apple findAppleById(long id){ return repo.findById(id); } public Apple ...
Bar Akiva's user avatar
  • 217
0 votes
2 answers
2k views

I have an eternal discussion in my work about why "error first" is "worng". In order to ensure what I try to tell with error first is the following code pattern: if condition: ...
Tlaloc-ES's user avatar
  • 387
1 vote
3 answers
1k views

Would anyone here recommend using debug statements such as the following in production quality code? I think these are personally one of the easiest to include or exclude, but they make the code hard ...
love4shells___'s user avatar
24 votes
8 answers
7k views

PEP 8 states the following about using anonymous functions (lambdas) Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier: # Correct: ...
N3buchadnezzar's user avatar
1 vote
2 answers
318 views

I have a general design question. Suppose I have a List: List<String> list = new ArrayList<>(); list.add("Str 1"); list.add("Str 2"); list.add("Str 3"); I ...
gaout5's user avatar
  • 41
2 votes
1 answer
485 views

I have been coding in python for a little over a year, and I have learned a lot and developed quite a few applications, in the process. I do not program for my profession, I simply program ...
NewCoder18's user avatar
2 votes
1 answer
347 views

I came across quite a subtle bug the other day, where there are two sections of similar code that were supposed to use different variables, but copy-pasting had lead them to use the same variable. I'...
Joel Gibson's user avatar
-2 votes
1 answer
563 views

In our line of work as software engineers, we can write code that assumes various things outside its scope or architectural boundary, in order to save performance, time, and on defensive coding ...
SpiritBob's user avatar
  • 105
6 votes
1 answer
843 views

I want to understand how Dependency Inversion gets rid of switch cases. Consider a service that needs to communicate with several databases. class StockUpdater { private final DataStore datastore; ...
A.Dumas's user avatar
  • 262
0 votes
2 answers
299 views

Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final ...
Pulkit Gupta's user avatar
0 votes
1 answer
88 views

Lets imagine some vendor code that we want to extend on our project level protected function getDefaultFormClasses() { return [ new FormClassA(), new FormClassB(), new ...
Jim Panse's user avatar
  • 408
2 votes
3 answers
706 views

Whenever I do temporary fix I want it to really be temporary. However, there is no way to come back to it later, as the fix might be a part of a bigger issue. Let's imagine that we have for some ...
Random Guy's user avatar
0 votes
2 answers
8k views

Is it usually recommended to define default values for Boolean arguments? I mean, is it usually recommended to define a function like this someFunction(a, b, x) { // a and b are strings, x is true ...
user90726's user avatar
  • 205
7 votes
9 answers
6k views

We have all heard of Don't Repeat Yourself and Write Everything Twice, but I've never understood why anyone would prefer the latter of those. Obviously you can go overkill with DRY, with the code ...
JensB's user avatar
  • 277
50 votes
6 answers
13k views

I am a home, amateur developer for 25 years and I just had a bright idea regarding comments. Like all such novel bright ideas, someone has probably already done it and there is probably a consensus on ...
WoJ's user avatar
  • 1,661
2 votes
3 answers
2k views

So, today I was reading a piece of code I found this function: Public Function FolderExists(sPath As String) As Boolean Dim FSO As New FileSystemObject On Error GoTo errHandler sPath = ...
DT1's user avatar
  • 209
4 votes
1 answer
93 views

I am writing a function that will download an HTML post. Having downloaded the string I will: strip off the html tags remove special encoding characters like \n remove trailing white spaces My ...
Eduardo's user avatar
  • 151
39 votes
17 answers
10k views

I have started in a new team. I have 20 years experience as a developer, and I have been in the role of a team lead in several projects. Normally I am very much pro code reviews, but I ended up in a ...
Pesho's user avatar
  • 540
4 votes
5 answers
408 views

In the past few months that I've been learning Javascript, I've wondered which is the better usage of functions: Functions that perform actions based on their arguments with no return value: const ...
literal240's user avatar
-3 votes
1 answer
619 views

We are building a software application for a client with a particular naming convention for REST services. For example if you use a POJO for your request or response in a REST service something like ...
Cesar Miguel's user avatar
0 votes
2 answers
200 views

Visual Studio often recommends the 'simple using' statement rather than brackets. However, which is actually better? I quite like the simple using statement, but I can see it potentially causing ...
user avatar
2 votes
4 answers
1k views

The consensus seems to be that it's better to put an if statement guard clause at the top of a method rather than using an if else statement. However, how can this be done with a void method and ...
user avatar
-5 votes
1 answer
1k views

If I have code that looks like this: int i; void functionA (){ for (i=0; i<10; i++){ functionB(); } } void functionB (){ for (i=0; i<20; i++){ doSomething(); } } ...
Noah Smith's user avatar
3 votes
4 answers
365 views

When I want to execute some code under the condition that a variable has one of two (or more) values I can use the OR operator: if (var == x || var == y) { DoSomething(); } But I'm not sure ...
jusaca's user avatar
  • 175
1 vote
3 answers
2k views

We have test code like: clickElement(a); clickElement(b); clickElement(c); that's repeated in many places, where clickElement is called 1 to 5 times in a row. Should we make a helper function to ...
Josh's user avatar
  • 175
1 vote
3 answers
187 views

Quite often I find difficult to decide between implementing operations as functions or as methods because I am not sure how to weight various well-known guidelines for this problem. I would like to ...
pob's user avatar
  • 119
3 votes
2 answers
1k views

This is the mess of imports currently at the top of my file: import argparse from copy import deepcopy from functools import cmp_to_key, partial from itertools import chain import math from ...
user avatar

1
2
3 4 5
22