coding-style

What application you recommend to start peeking to learn Python style?

Do you know any application, the more interesting/useful the better, to introduce a new person to Python language and the Python code style, but not necessarily to OO programing, so as to learn the subtleties and idioms of the language and surrounding community? I'm thinking along the lines of people that has worked with JavaScript, Jav...

In C#, is accessing the current object's properties through this.XYZ considered poor style compared to just XYZ

Is it a simple case of just never using the this.XYZ construct? ...

How important is it to indicate if a class implements an interface in Perl?

I've been discussing a code style issue with a friend. We have a series of packages that implement an interface by returning a specific type of value via a named subroutine. For example: package Foo::Type::Bar; sub generate_foo { # about 5-100 lines of code return stuff here; } So you can go: my $bar_foo = Foo::Type::Bar->gen...

How to indent Python list-comprehensions?

List comprehensions can be useful in certain situations, but they can also be rather horrible to read.. As a slightly exaggerated example, how would you indent the following? allUuids = [x.id for x in self.db.query(schema.allPostsUuid).execute(timeout = 20) if x.type == "post" and x.deleted is not False] ...

Coding style... error condition first or last?

Which is better in general in terms of the ordering? Do you put the fault condition at the top or bottom? if (noProblems == true) { // do stuff } else { // deal with problem } OR if (noProblems == false) { // deal with problem } else { // do stuff } ...

why are assignments in conditions bad ?

I am using NetBeans for PHP 6.5. In my code I frequently use the following type of command: if (($row = $db->get_row($sql))) { return $row->folder; } else { return FALSE; } Netbeans tells me that I should not be using assignments in the IF statement. Why ? ...

Java: Code Refactoring/Optimization

Please enlighten me: Which one do you prefer? Why? [Readability? Memory concern? Some other issues?] 1. String strSomething1 = someObject.getSomeProperties1(); strSomething1 = doSomeValidation(strSomething1); String strSomething2 = someObject.getSomeProperties2(); strSomething2 = doSomeValidation(strSomething2); String strSomeResult ...

How can I find methods without an explicit access modifier?

I am using FxCop and I would like to find all the methods or variables without an access modifier explicitly defined. For example: class MyClass { int myInt = 0; internal MyClass() { } } I would like FxCop to warn me that I didn't specify what access modifier will be applied to the variable "myInt" or the class "MyClass"....

Where do you declare variables? The top of a method or when you need them?

Hi, I am in sort of a dilemma (in a geekish way of course). I love to declare variables at the beginning of my methods, and usually order them in some logical way. The problem is, when the list gets long, it sort of gets out of hand. Should I just declare them when I need them? ...

IF statement formatting best-practise, what's your style?

Hi, Looking to improve my IF statement, and I want to keep my code looking pretty This is what I am currently doing, is it readable, any room for improvement? SomeObject o = LoadSomeObject(); if( null == o || null == o.ID || null == o.Title || 0 == o.ID.Length || 0 == o.Title.Length ) I don't have anyone to ask ar...

Inherited class quagmire, how to make this maintainable code

Hi, I want to create maintainable code, but this inheritance situation is causing me problems. The issue is with my 2nd database helper class named InitUserExtension. Since UserExtension inherits from User, I have to make sure that I mirror any changes in my InitUser helper to InitUserExtension. I really don't like this as its prone ...

Visual Studio C#-settings and StyleCop (MS Source Analysis)

Does anyone have settings for Visual Studio, in XML or a .vssettings-file, that is compatible with StyleCop? I've used the book Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries for guidance on what Microsoft finds to be the correct way to format C# and set my Visual Studio-settings accordingly. ...

Eclipse coding style checks as an Ant Task?

In Eclipse I can set all kinds of preferences for coding style. I'd like to be able to enforce these as an ant task to make the build break. Can anyone give me an example of how to enforce eclipse coding styles in an Ant task? (I KNOW about PMD, checkstyle etc - none of these EXACTLY match the eclipse preferences for coding style. I w...

HTML & CSS Coding Guidelines

We are contracting an external consultant out to generate XHTML (Transitional) and CSS for most of the major pages of a new project we are currently working on. I've been asked to put together a list of guidelines for them so that we can be sure that a certain level of quality can be expected. As a bit of technical background, we will b...

How would you write this block of code?

How would you write this block of code? A user can have 3 levels of permission: Suspend Lock Ban We have to decide if we want to delete the users account automatically. The business rules are as follows: Delete User if: suspend + lock + ban Warning Message if: suspend + lock So how would you write this code block? Keeping code ...

Should I return 'null' or an empty array?

Suppose you have a method that should create and return an array of some sort. What if the array doesn't get populated. Do you return an empty array or null/nothing? ...

Quick question about returning from a nested statement

If I have something like a loop or a set of if/else statements, and I want to return a value from within the nest (see below), is the best way of doing this to assign the value to a field or property and return that? See below: bool b; public bool ifelse(int i) { if(i == 5) { b = true; } else { b = false; } return b; } ...

Modifying existing code, what's your commenting style?

When you modify existing code, how do you comment the code? i.e. // changed code to ... // by: blankman // modified: 20081204 Looking for a nice format ... ...

Implementing and Enforcing Coding Standards

My team (of which I am the newest and most junior member) has increased in size from 3 to 9 developers in just about 1 year. Our primary product has increased in complexity and we are about to undertake a year long port/re-write to Silverlight. In the past there has been no specific style/standard enforced. I suggested to my boss that...

Is this idiom pythonic? (someBool and "True Result" or "False Result")

I just came across this idiom in some open-source Python, and I choked on my drink. Rather than: if isUp: return "Up" else: return "Down" or even: return "Up" if isUp else "Down" the code read: return isUp and "Up" or "Down" I can see this is the same result, but is this a typical idiom in Python? If so, is it some perf...