readability

Setting a boolean value based on an integer.

I found this statement is some old code and it took me a second to figure out... IsTestActive = (TestStateID == 1 ? true : false); Please correct me if I'm wrong but isn't this the same as this one?: IsTestActive = (TestStateID == 1); If it is, why would you ever want to use the first? Which one is more readable? (I think the latt...

Is late binding consistent with the philosophy of "readibility counts"?

I am sorry all - I am not here to blame Python. This is just a reflection on whether what I believe is right. Being a Python devotee for two years, I have been writing only small apps and singing Python's praises wherever I go. I recently had the chance to read Django's code, and have started wondering if Python really follows its "reada...

Code to calculate "median of five" in C#

Note: Please don't interpret this as "homework question." This is just a thing I curious to know :) The median of five is sometimes used as an exercise in algorithm design and is known to be computable using only 6 comparisons. What is the best way to implement this "median of five using 6 comparisons" in C# ? All of my attempts seem t...

How to correctly format PHP 'IF ELSE' statements?

It's been a long running issue that I've come across in many-a-hot-and-steamy coding sessions. One person codes this way another codes that way. So after much push and pull I'm curious... Is there any correct way of phrasing a PHP 'IF ELSE' statement? Personally I use the: if ($variable == 'setvalue') { $variable = executefunction...

Improving Code Readability

When it comes to code documentation, it is usually accepted that code should explain itself, and inline code documentation (excluding public API documentation) should only explain meta-code issues such as workarounds, explanations on why specific implementations were chosen, etc. How do you accomplish making your code more readable and ...

Which Method Do You Find More Readable To Output Dynamic HTML?

I'm imagining that this will come down to personal preference but which way would you go? StringBuilder markup = new StringBuilder(); foreach (SearchResult image in Search.GetImages(componentId)) { markup.Append(String.Format("<div class=\"captionedImage\"><img src=\"{0}\" width=\"150\" alt=\"{1}\"/><p>{1}</p></div>", image.Resolut...

Why should I capitalize my SQL keywords?

Duplicate of: http://stackoverflow.com/questions/292026/is-there-a-good-reason-to-use-upper-case-for-t-sql-keywords Simple question. I personally find a string of lowercase characters to be more readable than a string of uppercase characters. Is some old/popular flavor of SQL case-sensitive or something? For reference: select th...

Readability of nested AJAX callback functions

Please help me to refactore this Javascript code. There is big form for scheduled message sending(send date, reccurence type, end by date/qauntity, credits system - need to count total cost of scheduled sending plan in runtime). I'm writing Javascript validator for this form. There is an validation algorithm 1) check if send date time i...

Should We Use Long-Name Or Short-Name in JavaScript Coding?

There is a discussion about JavaScript coding in my work group. Some people argues that we should use long-name for better readability; the others believes that short-name should be favored to same bits-on-wire. Generally, it is about coding convention. One side believes that identifier such as "fAutoAdjustWidth" is OK, while others pre...

How do I write more maintainable regular expressions?

I have started to feel that using regular expressions decreases code maintainability. There is something evil about the terseness and power of regular expressions. Perl compounds this with side effect like default operators. I DO have a habit of documenting regular expressions with at least one sentence giving the basic intent and a...

C Registry Functions In Windows API

RegOpenKeyEx() I want to printf("Success") or printf("Failure") depending on if the function fails or succeeds How would I do such a conditional while keeping it neat and legible? I am wanting to stay away from this : if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HUGE LONG KYEY STRUCTURE HERE",0,KEY_SET_VALUE) != 0 ) { //CODE } ...

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 )

Is there extra overhead in using the object.ReferenceEquals method verses using ((object)obj1 == (object)obj2)? In the first case, there would be a static method call involved, and in both cases some form of casting to an object would be involved. Even if the compiler balances out those methods, what about inequality? (object)obj != n...

"public static" or "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, have a visibility keyword, then you'd want the visibility keyword to remain in the same ...

Is it worth the effort to have a function that returns the inverse of another function?

I have recently added a HasValue function to our internal javascript library: function HasValue(item) { return (item !== undefined && item !== null); } A during a convorsation with a coworker, we came up with the idea of also adding another function that would basically just be the inverse: perhaps HasNoValue, or IsNothing If we ...

Optimal tab size for code readability

Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8 spaces?) for code readability? In the different projects I've worked on, people seem to have vastly different standards. I can't seem to read 2 space indents, but companies like Google use it as a standard. Can anyone point to documentation, studies, or well...

Simple yet reoccurring naming problem

Let's say we have a method: public String wishes(Date birthday) { String birthayDateString = convertToString(birthay); ... } I wonder what's the best name to give to the string called now "birthayDateString". This string represents date converted to text. I can't name it "birthay" beause this name is alredy used. Do...

Is it poor coding practice to have a SQL table that contains a column with the same name?

Example: CREATE TABLE ErrorNumber ( ErrorNumber int, ErrorText varchar(255), ) This can result in queries that look like: SELECT ErrorNumber FROM ErrorNumber WHERE ErrorNumber=10 ...

Using delegates instead of interfaces for decoupling. Good idea?

When writing GUI apps I use a top level class that "controls" or "coordinates" the application. The top level class would be responsible for coordinating things like initialising network connections, handling application wide UI actions, loading configuration files etc. At certain stages in the GUI app control is handed off to a differe...

Reading "raw" Unicode-strings in Python

Dear all, 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 get into a latex-only format. Therefore, I have used python to recognise ...

Help on a better way to parses digits from a String in Java

I have a string which contains digits and letters. I wish to split the string into contiguous chunks of digits and contiguous chunks of letters. Consider the String "34A312O5M444123A". I would like to output: ["34", "A", "312", "O", "5", "M", "444123", "A"] I have code which works and looks like: List<String> digitsAsElements(String...