Coding style is a set of guidelines that helps readability and understanding of the source code.

learn more… | top users | synonyms (1)

0
votes
1answer
97 views

Which is preferred coding style to validate and return from a method [duplicate]

Which of the below is a preferred coding style (in c# .net) public void DoWork(Employee employee) { if(employee == null) return; if(!string.IsNullOrEmpty(employee.Name)) return; // Do ...
3
votes
6answers
1k views

More elegant way to avoid hard coding the format of a a CSV file?

I know this is trivial issue, but I just feel this can be more elegant. So I need to write/read data files for my program, lets say they are CSV for now. I can implement the format as I see fit, but ...
50
votes
17answers
6k views

Working on someone else's code

I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the ...
7
votes
6answers
367 views

Is it a problem to have different styles of HTML coding within team?

I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a ...
0
votes
2answers
487 views

Good or bad code? Or “a secret reason”?

I think this code: if(file_exists("amodule.inc.php")) require_once("amodule.inc.php"); is misleading because of the use of the require_once. I think that - to keep the logic and "wording" ...
3
votes
3answers
622 views

Avoiding boilerplate in PHP classes

I am working on a PHP code and as it grows getting more and more tired of repeating the same standard pattern again and again and again: class BolerPlate { protected $property1; protected ...
-1
votes
2answers
576 views

Interview Coding Assignments… how much do they account for? [closed]

So I've ran into a couple of companies that requires completing coding assignments before they give you a phone interview. I'm curious, do these coding assignments account for anything after the ...
26
votes
3answers
4k views

if ('constant' == $variable) vs. if ($variable == 'constant')

Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of: if ( 1 == $options['postlink'] ) Where I would have expected to ...
0
votes
0answers
47 views

Boolean condition before variable [duplicate]

I have noticed this style from time to time: if ( 0 == myVar ) Rather than: if ( myVar == 0 ) Is this just the individual programmers idiom? A defensive programming style? Does anyone know if it ...
9
votes
6answers
10k views

How are multiple values returned in Java?

Sometimes you want to return multiple values from a function. How is this normally done in Java? One option is to use an array, like this Python snippet that returns a list or tuple: value, success ...
1
vote
2answers
446 views

Arguments for conforming to PSR-2

I am trying to convince the lead developer of an open-source project I'm contributing to, to conform to the PSR standards (PSR-2 in particular) created by the PHP Framework Interop Group. He is ...
12
votes
2answers
317 views

is there any elegant way to analyze an engineer's process?

Plenty of sentiment exists that measuring commits is inappropriate. Has any study been done that tries to draw in more sources than commits - such as: browsing patterns IDE work (pre-commit) idle ...
6
votes
3answers
298 views

Is there any situation in which it would be appropriate to use unless… else?

This construction is considered wrong unless #.. else #.. end This is for the general reason of double-negative confusions. It translates to: if not #.. if not not #.. end We all agree ...
3
votes
3answers
474 views

Which is the better: a <= b or a < b+1 [closed]

For loops are usually inclusice, exclusive, meaning that you start at the bottom, and stops when you reach, but don't to the top. In Python: for i in range(0,a): print(i) would print 0 through ...
4
votes
2answers
2k views

Excessive use “this” keyword in Java [duplicate]

The this keyword is primarily used in three situations. The first and most common is in setter methods to disambiguate variable references. The second is when there is a need to pass the current ...
2
votes
1answer
623 views

Is nesting typedefs a good style?

Let's say I have a namespace my and this namespace contains a class foo. What should I prefer nesting typedefs into my class or hold it in my namespace? namespace my { class foo { // some stuff ...
4
votes
4answers
283 views

How do you proactively guard against errors of omission?

I'll preface this with I don't know if anyone else who's been programming as long as I have actually has this problem, but at the very least, the answer might help someone with less xp. I just stared ...
17
votes
9answers
8k views

Why are people so strongly opposed to #region tags in methods?

I hear a lot about keeping methods short and I've heard a lot of programmers say that using #region tags within a method is a sure sign that it is too long and should be refactored into multiple ...
9
votes
7answers
1k views

Temporary variables vs line length requirements

I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble. Fowler recommends that you replace temporary ...
5
votes
4answers
558 views

How can I stop myself overwriting member variables with 'new' ones?

The bulk of my programming experience has been with C++ and (shudder) FORTRAN (I'm a scientist not a programmer as such, but I do my best). I've recently started using python extensively and find it ...
44
votes
3answers
1k views

Coding Style for Visually Impaired Programmer

I am visually impaired. With glasses I see well enough to drive, but at the font size I'm comfortable working at I can only see about 15 lines of 100 characters at a time. This has affected my ...
5
votes
3answers
749 views

What are the names for various forms of camel-case style naming?

For the purposes of communicating coding styles to my co-workers, what would I formally call the following variants of camel case? camelCase and CamelCase Notice that the former version ...
2
votes
2answers
1k views

Should I use semicolons to delimit Scala statements?

I'm used to delimit statements by a semicolon from Java, so naturally I do it in Scala code too. I also feel that the code is easier to read, because it's evident where one statement ends and another ...
3
votes
2answers
255 views

How can I keep current with Python coding style?

I've been using Python since version 2.2. I do pick up new language constructs like for example with statement or dictionary/set comprehensions. However, I've realized that even though I'm being ...
1
vote
2answers
310 views

How much functional programming expertise can programmers be expected to have? [closed]

I'm coding in a non-functional language with functional mechanisms (C# to be specific, but you could substitute, say C++ and use function pointers, or what have you) on a small team. It's my habit to ...
1
vote
2answers
637 views

What is the exact syntax of inline?

CASE 1 (Definition and declaration in same source file) Suppose both my prototype and definition of global function is in .cpp file. Where should I write inline keyword to make compiler know? In ...
50
votes
10answers
7k views

Is the 80 character limit still relevant in times of widescreen monitors?

on a widescreen monitor one can easily see more than 80 characters at a time, without scrollbars. even linus torvalds sees the 80 character limit as outdated. so, is the 80 character limit still ...
3
votes
1answer
372 views

Maintaining code-style conventions for large projects [closed]

For a while I've been maintaining an ad-hoc script to check code style against our project's guidelines. I'm aware of AStyle/Uncrustify and have used them, but they are best for once-off code-style ...
4
votes
3answers
300 views

Placeholders in strings

I find that I sometimes use placeholders in strings, like this: $ cat example-apache <VirtualHost *:80> ServerName ##DOMAIN_NAME## ServerAlias www.##DOMAIN_NAME## DocumentRoot ...
9
votes
4answers
693 views

What makes for “good style” in Java? [closed]

I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it. I've been programming in Java ...
19
votes
2answers
1k views

Is it a good idea to provide different function signatures that do the same thing?

Here is a C++ class that gets constructed with three values. class Foo{ //Constructor Foo(std::string, int, char); private: std::string foo; char bar; int baz; }; All of ...
2
votes
3answers
281 views

Should I make a variable readonly when I modify it, but I don't actually set it outside of the constructor?

Background: I was writing some code. It looked something like this: class X { private List<int> _myList = new List<int>(); public void MyMethod(int x) { ...
9
votes
2answers
1k views

Is this awkward spacing some type of style?

In reading another programmers code, he uses a format I have never seen. E.G. namespace MyNs.HereWeAre {//tab here for some reason public class SomeClass ...
5
votes
2answers
899 views

C++11 Header-only Library: in-class body vs. out-class body code?

BACKGROUND:optional Since 2002 I've been slowly building my own Windows Native C++ library. And let's just say that I have jumped 150KLOC (reusable code) having everything I need and the kitchen sink ...
4
votes
6answers
3k views

Clarification of “avoid if-else” advice [duplicate]

The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need. Now, this if/else ...
2
votes
4answers
3k views

Microsoft's coding standards for ASP.NET controls

I cannot find any naming standards/conventions in MSDN for naming ASP.NET controls. One of the following standards tends to be used by programmers: lblAddress AddressLabel Address According to ...
0
votes
1answer
282 views

How to format this line according to PEP 8? [closed]

I'm trying to adhere to PEP 8, with a 78 character limit on the length of my lines. I have the following statement: startTime = time.strptime(request.GET.get('st', (dt.datetime.now() - ...
3
votes
3answers
371 views

Blank lines in C

I'm working through K&R and I notice that their code is extremely tightly spaced. I haven't developed C since at University, but professionally most source from other languages I've worked in has ...
58
votes
16answers
5k views

Is inconsistent formatting a sign of a sloppy programmer?

I understand that everyone has their own style of programming and that you should be able to read other people's styles and accept it for what it is. However, would one be considered a sloppy ...
62
votes
15answers
7k views

Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code: If (a AND b) OR (c AND ...
0
votes
3answers
180 views

which style of member-access is preferable [duplicate]

the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example: template<typename T> class foo_1 { ...
27
votes
2answers
15k views

What's wrong with relative imports in Python?

I recently upgraded versions of pylint, a popular Python style-checker. It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying ...
8
votes
7answers
576 views

Commenting/In-Code Documentation Styles

This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else. I have a teacher who says we should explicitly list each parameter ...
2
votes
2answers
230 views

Helper Methods Placement [duplicate]

Here's a question that's always bugged me. I'm going to use java as an example because I've almost never run into a problem in java where I didn't need to use helper methods in its class structure. ...
3
votes
3answers
1k views

articles in variable names and hard-coding strings

re-edited by author: no this is not 2 questions. This is one question about code review questions containing two separate points. Please do not edit my question. For naming variables, the two sides ...
5
votes
3answers
423 views

Coding Convention: C++ Header/Interface Files

I'm reading through a PDF on C++ programming from this page on Stanford's site. It says that when you're creating a C++ header file for a library interface, use a #ifndef preprocessor command to make ...
2
votes
4answers
177 views

function exit condition on parameter consistency check [duplicate]

When checking for parameter consistency a the top of a function body, what is the best strategy? This one: protected void function(Object parameter) if (parameter == null) return; ...
6
votes
3answers
476 views

Is the usage of internal scope blocks within a function bad style?

There are some (quite rare) cases where there is a risk of: reusing a variable which is not intended to be reused (see example 1), or using a variable instead of another, semantically close (see ...
10
votes
5answers
1k views

What are the downsides of mixing tabs and spaces? [duplicate]

The advantage of using tabs for indentation is that people can configure their editor to use the tab width they are comfortable with. The only argument against this seems to be that people don't want ...
33
votes
13answers
6k views

In languages that don't allow underscores in integer constants, is it a good practice to create a constant for 1 billion?

In languages that don't allow underscores in integer literals, is it a good idea to create a constant for 1 billion? e.g. in C++: size_t ONE_BILLION = 1000000000; Certainly, we shouldn't create ...