Questions tagged [code-readability]

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own.

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own. This includes Coding Conventions, positioning of white space, declaration of variables and among other coding practices.

337 questions
1
vote
2 answers

Complex If conditions. Bad practice?

Context: I am trying to make sure my player can only sprint if: They are moving forwards, The "Sprint" key is pressed, They are grounded. if ((Input.GetAxis("Vertical") == 1) && Input.GetButton("Sprint") && isGrounded) { …
4Ves
  • 53
  • 8
1
vote
1 answer

Proper use of "return" in functions

I am writing a method and I want it to stop if something is not ok (it will go back to another method that has a while loop). I wonder if I should use "return" to stop this method to run further or if there's something better. This method is really…
Ranma0020
  • 13
  • 4
1
vote
1 answer

Preferred way to model nullable TIMESTAMP with a Gorm model?

I'm implementing a Gorm model to access a table in MySQL. It is something like this: import ( "time" ) type MyModel struct { // ...some attributes... CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time } I am wondering if it…
germanio
  • 861
  • 1
  • 17
  • 27
1
vote
2 answers

Extracting information from a collection - readablility or performance?

Sometimes from a collection, several information needed to be extracted. But what is the best practice to do that? Readability over performance Should the collection have to be iterated for any information separately? Then we would have n-time loops…
1
vote
2 answers

Is there any significant performance impact from too many variable declarations?

For readability's sake, I often find myself declaring new variables for data I already have in hand, and was wondering, does this have any major impact in performance? Example of what I do: const isAdult = this.data.person.age >= 18; const…
Lucas_Nt
  • 116
  • 1
  • 7
1
vote
2 answers

How To Write Readable If Statements For Input's Validation?

I'm encountered silly, but still significant problem. I'm creating validation for "Sign Up"-like page. I need to check that inputted values aren't harmful and fit my needs. Thanks to Fuel framework it's easy enough. Next... I need to check also that…
daGrevis
  • 21,014
  • 37
  • 100
  • 139
1
vote
3 answers

Storing Hash Data Externally in Perl

I'm currently working to refactor a script that has a reliance on three hashes (simple hashes), initialized at the beginning of the script. In total, these hash values take up over a hundred lines in the script. In order to improve overall…
Cooper
  • 679
  • 3
  • 9
1
vote
1 answer

Raising errors: Ugly code... Better way to write?

def positive_int(value): try: ivalue = int(value) except: raise argparse.ArgumentTypeError("%s is an invalid positive int value" % value) if ivalue <= 0: raise argparse.ArgumentTypeError("%s is an invalid positive…
Snusifer
  • 485
  • 3
  • 17
1
vote
1 answer

Avoiding code duplication in F# when making a form based app for multiple data types

I am currently making an app in F# with fable elmish architecture where the record types are as follows (cut down to save space but you hopefully get the idea). type NewOriginMerdEntry = | AddOriginMerdID of string | AddMerdNumber of int …
Simplexity
  • 77
  • 1
  • 3
1
vote
1 answer

Using parameters vs global variables -- Code readability / maintainability

I'm trying to understand the sweet spot between readability vs repeating myself in my code. I'm creating Conway's game of life in Javascript. My functions use many of the same variables over and over again like so... const BOARD_HEIGHT = 50 const…
1
vote
1 answer

Readability of Small functions where new variable declaration is not required

I need some advice regarding the code structure for small methods. Below is a method from the Java API. Collections.class private static Random r; public static void shuffle(List var0) { Random var1 = r; if (var1 == null) { r =…
1
vote
1 answer

VBA: When to use a function vs putting code in the main sub

I'm trying to automate the process of compiling quarterly data from different files into a single Excel workbook (this needs to be done each quarter). Now I have come to a point where I wondered if I should keep all code in the main sub or if I…
NoNameNo123
  • 625
  • 1
  • 8
  • 17
1
vote
2 answers

Is there any consensus whether reassignment of method parameter is good or bad practice?

I want to write a method like this: def method(self, long_api_parameter_name=None): if long_api_parameter_name is None: long_api_parameter_name = self.DEFAULT_X return self.another_method(long_api_parameter_name) However I have…
abukaj
  • 2,582
  • 1
  • 22
  • 45
1
vote
2 answers

How to enumerate through the DataTables of a DataSet starting at the second table in the collection using C#

A for loop starting at index 1 is an obvious answer. I'm sure there are many other ways to do this. But what is the most readable way? The question is using C# 4.0. LINQ is optional.
Mark
  • 5,223
  • 11
  • 51
  • 81
1
vote
1 answer

Differentiate logging informations of multiple instances of the same class

I'm trying to log the methods call chain of some classes instances of a Java program using Log4j2. Each instance will behave differently based on the inputs they will recive (obviously). The problem I'm facing is differentiating the logging messages…
el.Quero
  • 25
  • 5