How to bring out an important unary minus in the code?

I have an entity that represents a reservation of some quantity. There will also exist entities where this property is negative indicating a lack of availability for the reservation. The logic will then decrease the quantity of a reservation with a p

Using static imports and code readability?

Would it be considered worsening the future readability of the code if I used them throughout the code? For example using: import static java.lang.Integer.*; so I can use this code int a = parseInt(scanner.nextLine()); when should you use static impo

Does C # have a way of & amp; & amp; =?

I have several booleans I need to check and turn into a single boolean for readability: bool myBoolean = 5 == 5 && "string" == "String" && true && false && CheckSomethingElse(); Is there a way I can brea

how to organize test data in integration tests

I am working on a large test project consisting of thousands of integration tests. It is a bit messy with lots of code duplication. Most tests are composed of several steps, and a lot of "dummy" objects are created. With dummy I mean something l

Temporary debug code disabling

I have an habit to use code like this for debugging blocks that aren't very trivial to write: if(0) { // debugging code } The problem is "warning C4127: conditional expression is constant". I am keeping comments for old code that can be deleted

Replace repeated lines of code with a function

I work on embedded C and am trying to refactor code to improve readability and optimize ROM used in my project. I have this 3 lines of code repeats many times in switch-cases to update a particular edit box on a particular screen name. EbSetText and

performance and readability on repeated functions

I have a code void Foo() { auto index = currentIndex(); if (index.isValid()) index.doSomething(); } another option void Foo() { if (currentIndex().isValid()) currentIndex().doSomething(); } The second one is more readable for me. But how is its perfo

Best / easiest way to declare relay orders

I've been trying to find a nice neat and succinct way to declare RelayCommands in my ViewModels. The best I can come up with is: public class MyViewModel { public ICommand StopCommand { get; private set; } public MyViewModel() { StopCommand = new Rel

K & amp; Does R teach bad readability?

It has been a while since I looked at C (still learning) and I just got back into the K&R book. I just had a go to Exercise 5-3 (p107). Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s,t) copies the string t to the

Why is there so much bad code indented?

The more I browse the code to open source projects in languages that aren't Python, the more I realize that it seems a lot of programmers don't believe in proper indentation. (I won't mention any projects specifically to avoid having anyone take this

How to format the code in search reports

I am currently writing a formal research report, and I'll be including code with this report. Question: Is there an accepted way of displaying code in research reports? I'm thinking both in terms of font, spacing, et cetera, and whether the code shou

Simplification of the if instruction logic

I have seperated out a test to determine if two schedule items overlap because of the unreadability of it. Is there any application to assist in simplifying a logic statement? Example: (originally a faulty example, but exposes reasons I request this)

Reading & ldquo; gross & rdquo; Unicode-chains in Python

I am quite new to Python so my question might be silly, but even though reading through a lot of threads I didn't find an answer to my question. I have a mixed source document which contains html, xml, latex and other textformats and which I try to g

& ldquo; static public & rdquo; or & ldquo; static public?

A minor point about function declaration keywords in PHP: If you've got a class method that's static, should the static keyword come before or after the visibility keyword (public, protected, private)? Assuming all your methods, static or otherwise,

Formatting an if statement for readability

What's the best way to format this for readability? if (strpos($file, '.jpg',1) && file_exists("$thumbsdir/$file") == false || strpos($file, '.gif',1) && file_exists("$thumbsdir/$file") == false || strpos($file, '.png',

Improve the readability of Python?

I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python f