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
1 vote
1 answer
127 views

If you create a function, which should make the use of typeconversions more easy, but it maybe leads to more errors, would implement it globally, and what may speaks against it - when the readability ...
mayen's user avatar
  • 13
2 votes
2 answers
552 views

for example, Suppose I have a 2d array: let filterArr=[ [1,1,0,1,1], [0,1,1,1,0], [1,1,0,1,0] ]; I want to find and store the index of column that all are 1, i.e.:position 1 and 3, and the ...
ocomfd's user avatar
  • 5,760
3 votes
0 answers
94 views

I'm working on a website that has a section that shows the company's stock details and investor-related data. This data is retrieved through scheduled SOAP API calls. I created two scheduled tasks ...
7asobate-'s user avatar
0 votes
1 answer
169 views

For example, I have a toggle button, which would show the current selected element, and would show next element when it is clicked, and it can loop back to first element. I have 2 ways to store the ...
ocomfd's user avatar
  • 5,760
3 votes
1 answer
266 views

I work on a small team (2 primaries with one or two other occasional contributors) on a project/product that spans a number of separate platforms. We do embedded firmware in straight C on Arm0 chips. ...
Travis Griggs's user avatar
2 votes
2 answers
202 views

For example, suppose I have 2 arrays: let arr1=[5,2,1]; let arr2=["abcde","ab","a"]; my work is simple : to check if length of strings in arr2 are larger than corresponding element with same index in ...
ocomfd's user avatar
  • 5,760
3 votes
6 answers
889 views

So I was recently given a coding assignment from a large financial firm, and I thought of two ways to solve the problem. One of the ways involved 1 outer for loop and 1 inner for loop. In this case, ...
Tyler M's user avatar
  • 89
14 votes
6 answers
4k views

To avoid magic numbers, we often hear that we should give a literal a meaningful name. Such as: //THIS CODE COMES FROM THE CLEAN CODE BOOK for (int j = 0; j < 34; j++) { s += (t[j] * 4) / 5; } ...
Jonas Kahn's user avatar
0 votes
3 answers
478 views

I have a bunch of if statements written in PHP for a project I'm working on. The pattern is that when the $price increases by 5 cents every time magazines are increased by 10. When the amount of ...
SpookyBoogy's user avatar
0 votes
2 answers
158 views

I'm adding mod support for a game I'm working on. I parse a data file that looks something like this: "requirements": { "is_class": { "class": "warrior" }, "is_in_faction": { "faction": "...
Michael.Aaron.Williamson's user avatar
3 votes
2 answers
141 views

For example, I have a for loop, which element 0 has additional function to run compared with other elements, my question is, should the additional function be: 1.place inside for loop for(int i=0;i&...
ocomfd's user avatar
  • 5,760
17 votes
6 answers
9k views

This is the most popular way (it seems to me) of checking if a value is in an array: for (int x : array) { if (x == value) return true; } return false; However, in a book I’ve read ...
Danila Piatov's user avatar
4 votes
2 answers
429 views

For example, it is common to see games with game loop and states: stateChanged(){ switch(state){ STATE.PLAYER_SELECT_CHARACTER: this.currentController=new PlayerSelectCharacterController()...
ocomfd's user avatar
  • 5,760
1 vote
2 answers
284 views

For example, suppose I have a ZipCode class: public class ZipCode{ public value String value; public boolean validateFormat(){ ... } public otherMethod1(){ ... }...
ocomfd's user avatar
  • 5,760
4 votes
3 answers
3k views

For example, if 2 classes depend on each other, it is a kind of circular dependency and should be avoided. How about methods? for example, if I have 2 methods which call each other: public void ...
ocomfd's user avatar
  • 5,760
3 votes
1 answer
121 views

For example, to convert between g and kg, I have a constant 1000: public static final float G_TO_KG=1000; . . . this.result = someResult*1000; I found G_TO_KG always bind to operator '*'. So my ...
ocomfd's user avatar
  • 5,760
5 votes
3 answers
9k views

For example, to store whether sound is on, I have a boolean originally named "isSoundOn": private boolean isSoundOn=true; however, the default value of boolean is false, but I want my application to ...
ocomfd's user avatar
  • 5,760
1 vote
2 answers
130 views

When define a locale text map, I can use: 1.locale key first { "en":{ "WELCOME_TO_USE_THIS_APP":"Welcome to use this app,...", "SOME_OTHER_TEXT":"fsdfsf..." }, "es":{ "...
ocomfd's user avatar
  • 5,760
0 votes
2 answers
260 views

I'm applying Clean Architecture + DDD (maybe) in my project (web Application + REST API). The good thing I learned from the Clean Architecture is using "Interactors" to show business use cases in my ...
Hung Doan's user avatar
  • 109
1 vote
3 answers
353 views

Say we start with a base class that states if an object is valid or not (included one interface and two child classes for discussion purpose), like: interface IValid { bool IsValid(); } public ...
penpen's user avatar
  • 101
0 votes
2 answers
758 views

Is there a reason why Python developers (both maintainers of Python itself and authors of modules) tend to pass special strings as arguments to functions instead of defining symbols for the same ...
Mr. Lance E Sloan's user avatar
2 votes
1 answer
196 views

I want to extract lines from a stream that are preceded by the character L. The list comprehension below does the job, but calls next on the stream inside the comprehension in a way I've never seen ...
Elliot Gorokhovsky's user avatar
2 votes
1 answer
497 views

For example, for oauth, I may need to copy and paste oauth and oauth callback code like it (assume Client is the framework I use, I don't use real framework like google because I want to simplify the ...
ocomfd's user avatar
  • 5,760
17 votes
4 answers
17k views

Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
fhorrobin's user avatar
  • 281
174 votes
24 answers
27k views

I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical ...
auden's user avatar
  • 1,656
1 vote
2 answers
409 views

I'm working on a large codebase whose core modules are in C and extension modules are in C++. We have a coding convention for C code but I'm being told that we need to enforce the same coding ...
user3834459's user avatar
6 votes
3 answers
2k views

I'm writing a CSV parsing library in C and am considering whether to express error codes as return values or as parameters passed by reference. For example, here are the signatures for the function ...
Govind Parmar's user avatar
-3 votes
1 answer
74 views

The problem is like there are few restaurants and few delivery guys available. Each restaurant has a meal order and the delivery guys are to be assigned to the restaurant. Now there may be many ...
Shashwat Kumar's user avatar
-2 votes
1 answer
2k views

Often I came across situations like this, how to write this code in a neat and clean way. One more issue I find here is performance as I am iteration a list and then it's properties. Edit : - while ...
ifelse.codes's user avatar
6 votes
1 answer
875 views

Sometimes I can see method definition like: public User findUserById(int id){ } But my justification is, isn't "(int id)" already include the information of "ById"? is it better to have naming just ...
ocomfd's user avatar
  • 5,760
1 vote
2 answers
4k views

Say I have class with a boolean member variable fancy: public class MyClass { private boolean fancy; } Case 1. I could the define the setter and getter as follows: // getter public boolean ...
StaticBeagle's user avatar
2 votes
6 answers
2k views

According to Why should I prefer composition over inheritance?, I should prefer composition over inheritance. But what if I need to access the interface and class member in generic way? For example, I ...
ocomfd's user avatar
  • 5,760
14 votes
3 answers
19k views

C# 6 added auto-property initializers and so we can do private List<LinearLayout> layouts1 { get; } = new List<LinearLayout>(); Is this better or worse than private readonly List<...
dumbledad's user avatar
  • 317
3 votes
4 answers
1k views

According to Should we avoid language features that C++ has but Java doesn't?, I know it is horrible to write C++ as if Java, mostly because it drops the beneficial features of C++ languages. But ...
ocomfd's user avatar
  • 5,760
-2 votes
1 answer
315 views

I recently reviewed code that read as follows: if (!condition) { do_something(); } else { do_something_else(); } In other words, in the if statement we checked that a condition was false, and ran ...
Nate Rook's user avatar
2 votes
3 answers
559 views

Sometimes, I would write if-statements with conditions like it: if(a-b>0){ } but in fact, I can move 'b' from left hand side to right hand side: if(a>b){ } Similar cases like 'a-b!=0','a-b<=...
ocomfd's user avatar
  • 5,760
0 votes
1 answer
1k views

I was working with some API which was used internally, and while looking at their code I found something like this: public class Parent { @Data public static class Child { private ...
engma's user avatar
  • 111
1 vote
2 answers
202 views

I am relatively new to HTML/JS and am very much an amateur programmer. I have created a web app that works but I can't help but feel that the code is a spaghetti mess! I have been looking for JS/HTML ...
SimpleOne's user avatar
  • 199
-1 votes
1 answer
195 views

According to Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?, I should split long functions into smaller functions even if they ...
ocomfd's user avatar
  • 5,760
18 votes
5 answers
10k views

In the past, I've typically done most of my manipulation of an object within the primary method it's being created/updated, but I've found myself taking a different approach lately, and I'm curious if ...
JD Davis's user avatar
  • 1,387
6 votes
4 answers
10k views

I'm trying to parse readable data from PDFs and I keep ending up writing code like the following: if (IsDob(line)) { dob = ParseDob(line); } else if (IsGender(line)) { gender = ParseGender(...
Levi H's user avatar
  • 177
2 votes
2 answers
734 views

So I've seen many different methods used for this in different librarys, and I want to get a sense of which one may be preferred (or perhaps it's strictly personal preference/case by case). Just as an ...
ricco19's user avatar
  • 123
11 votes
4 answers
867 views

I have a project that is sufficiently large in size that I can't keep every aspect in my head any more. I'm dealing with a number of classes and functions in it, and I'm passing data around. With ...
user7088941's user avatar
-2 votes
1 answer
1k views

What name should I give classes which are just for configuration? For example, when using JAX-RS, every application is required to have an Application class which extends the superclass javax.ws.rs....
vikarjramun's user avatar
0 votes
1 answer
92 views

For example, suppose my app have some localization texts. My question is, should I load appropriate locale at start: var locale=userPrefs.getLocale(); localeStringMap=getLocaleTextFromFile("...
ocomfd's user avatar
  • 5,760
-5 votes
1 answer
703 views

At my new work I am dealing with a quite big C/C++ project (50k lines in multiple files). I usually "draw" what the code is doing to understand its functioning but this time I am struggling a bit ...
Fra93's user avatar
  • 101
1 vote
1 answer
809 views

Since when I used smarty I always tried to separate logic statements from html tags, so my approach to blade would be to write: template.blade.php <div> <div> @if ($something == true)...
Crayon's user avatar
  • 119
4 votes
1 answer
310 views

We have one table meta where there is key and value so each of the row represents one component or service and then we have api system which manages the metas database. And it was going pretty well ...
ujwal dhakal's user avatar
4 votes
5 answers
1k views

The title might be a bit vague, so let me explain. Let's assume we have a function that does something (changes state of the program), for example a function that creates a file. That function returns ...
leonz's user avatar
  • 226
4 votes
2 answers
652 views

There's a common code smell involving long methods with the most common answer being that methods should be really small, less than 50 lines per say (or 20). I understand why this is because it ...
Jake's user avatar
  • 151

1
3 4
5
6 7
22