FAQ Database Discussion Community


What are the alternatives to creating a closure here?

javascript,closures,code-readability
Suppose we have a list of simple objects: var things = [ { id: 1, name: 'one' }, { id: 2, name: 'two' }, { id: 3, name: 'three' } ]; And we need to iterate through these objects and register them as parameters for some later event. The naive...

Is it mandatory to enclose an entire ternary operator statement in parenthesis in this statement?

php,ternary-operator,parentheses,readability,code-readability
For example in the following statement, $class = ( is_array($tagClasses) ? 'class="'.implode(" ",$tagClasses).'"' : '' ); is the outermost parentheses only for readability or does it really have any other purpose? I think it is for readability and code-aesthetics only, unless you have other things happening in the same statement,...

Is there a character I can use to improve large number legibility in PHP code?

php,numbers,code-readability,human-readable
In Perl code, you can put underscores in large numbers to improve legibility. For example, the number 123456789 is equivalent to 123_456_789, which helps the coder understand what number it represents. Is there a character in PHP that I can use for the same purpose? I have tried commas and...

Pipe a single object and process it without For-EachObject

powershell,code-readability
Original Question I a piping a single string and processing it with For-EachObject as follows: "Test" | % { $_.Substring(0,1) } It seems wrong to process a single piped item using For-EachObject, partly because it's misleading to future code maintainers. I don't know any other way, though, to capture the...

Suggestions for improving the readability of this code

c,code-readability
I am not sure whether I should ask this here or to some other StackExchange site, but I will go on... Please migrate if it is not suitable here) I am reviewing a code. Requirement is to call a function nnumber of times with argument ranging from 0 to n....

Should you use named functions when developing a JavaScript library?

javascript,debugging,coding-style,introspection,code-readability
For example: module.exports = { myLibraryFunction: function myLibraryFunction() { ... } } The disadvantage is obvious. It's not very DRY, which means it can easily become out-of-sync if you're not careful. It also makes your code a little more verbose. So what are the advantages? Is the tradeoff worth it?...

Readability in nested conditional statements

python,conditional-statements,code-readability
I'm currently writing a program in Python to model projective geometry, and the congruence function for a projective point is looking rather nasty. (for anyone interested, two projective points are congruent if they both lie on a single line passing through the origin.) class Point(object): def __init__(self, a, b, c):...

How to use constant powers of 2 readable in c++?

c++,binary,coding-style,constants,code-readability
I need several integer constants with 2^n and 2^n - 1 in my GNU c++ code. What is a good practise to keep the code readable? The code uses decimal values at the moment 4294967296 and 65536 which is hard to debug in future. 2^12 is not implemented in standard...