clean-code

Code a stored procedure that get one single record or all records from a table

I'm searching for the cleanest solution here. I would like to code a stored procedure that should retrieve one record if the proper key is passed in input, or all the records if it is called without parameter. Table FOO has two fields, CODE and DESCRIPTION. In Sql server 2008, i usually create a stored procedure with like this: CREATE...

Cleaner way of manually updating multiple rows

I wanted to see if there is a cleaner and more effective way of writing the SQL statement below. (MySQL) UPDATE login SET is_admin=1 WHERE memberid = 1 OR memberid = 6 OR memberid = 10 OR memberid = 12 OR memberid = 7 OR memberid = 3; Simply want a nicer way of solving it. Optimize :) ...

Metaprogramming - self explanatory code - tutorials, articles, books

Hello everybody, I am looking into improving my programming skils (actually I try to do my best to suck less each year, as our Jeff Atwood put it), so I was thinking into reading stuff about metaprogramming and self explanatory code. I am looking for something like an idiot's guide to this (free books for download, online resources). A...

SafeHTML alternative? It doesn't seem to be available anymore

Tried various sites. All download links point to pixel-apes.com which no longer seems in existence. Any alternatives you guys like? I'm planning on using Markdown if that affects anything. Thanks! ...

how to write clean code in c# language and improve quality of code.

how i can improve our code quality and write clean code. if i write a unclean ugly code then how i can migrate as a good code (beautiful and clean). ...

How to clean and simplify this code?

After thinking about This Question and giving an answer to it I wanted to do more about that to train myself. So I wrote a function which will calc the length of an given function. Th given php-file has to start at the beginning of the needed function. Example: If the function is in a big phpfile with lots of functions, like /* lots o...

Tool that shows unit dependencies for Delphi 2010 or Delphi 7 program

We're trying to untangle a hairball of 100's of units, removing some. It would be helpful if there was tool that would show us what units were explicitly using unit X. Penganza doesn't seem to have a report that does that. (Although it has lots of other useful reports.) Can anyone suggest a tool or strategy for doing this, other than ...

Better way to clean this messy bool method

I'm reading Fowler Clean Code book and I think that my code is a little messy, I want some suggestions: I have a simple business requirement that is return the date of new execution of my Thread. I've two class fields: _hour and _day. If actual day is higher than my _day field I must return true, so I'll add a month to "executionDate" ...

A or B, not both, not neither

Ever since reading Clean Code I have been trying to keep my code descriptive and easy to understand. I have a condition where either A or B must be filled in. But not both. And not neither. Currently the if statement to check for this condition is hard to follow at a glance. How would you write the following to make it clear at a gl...

When are comments "too much", and when are they not enough?

There is an on-going minor debate where I work about the efficacy of comments within code. One of the leads instructed his developers not to use comments as they are too "old fashioned", and a couple of other developers indicated that they never use comments because they feel all they do is clutter up the code. I have always pretty much...

Cleanest way of choosing between two values in Python

Dicts in Python have a very nice method get: # m is some dict m.get(k,v) # if m[k] exists, returns that, otherwise returns v Is there some way to do this for any value? For example, in Perl I could do this: return $some_var or "some_var doesn't exist." ...

What are good tactics to do function extraction in Objective-C to create clean code?

In the book Clean Code the author recommends breaking large methods into small functions that do one specific thing. In languages like Java this translates to pretty, readable code. public static String renderPage(PageData pageData) { includeHeader(pageData); includeContent(pageData); includeFooter(pageData); return page...

Returning from a method with implicit or explicit "else" or with a single "return" statement?

Some people consider multiple return statements as bad programming style. While this is true for larger methods, I'm not sure if it is acceptable for short ones. But there is another question: Should else explicitly be written, if there is a return statement in the previous if? Implicit else: private String resolveViewName(Viewable v...

What's the more elegant way to declare a const in C#

I'm refactoring a library in C# and I found a lot of upper case constants: INTERVAL, TIME, SECONDS. I think this a kind of unnecessary, and personally I prefer declare everything with camel case. Exist some exactly definition about the better way? ...

Pythonic way of repeating a method call on different finite arguments

I was staring at a piece of Python code I produced, which, though correct, is ugly. Is there a more pythonic way of doing this? r = self.get_pixel(x,y, RED) g = self.get_pixel(x,y, GREEN) b = self.get_pixel(x,y, BLUE) t = function(r,g,b) if t: r2, g2, b2 = t self.set_pixel(x,y,RED, r2) self...

Groovy - Cleaning up functions

Hi guys, I have a gross looking function and am wanting to clean it up. All it contains is some maps, a for loop, and if statements. Basically I have a map that I would like to grab only certain information from but one of the keys that I need from it changes by one number in each map. I was thinking maybe a simple switch statement or...

One function argument or instance variable [Clean Code book]

Hi everyone, I'm reading Uncle Bob's "Clean Code" book and constantly finding contradictory statements. Here is one of them. Book claims that we should use as few function arguments as possible, so it's more preferably to use function without any arguments to function with one argument and after this claiming there is suggestion how to r...

Where to store feedback UI data in ASP.NET MVC 2?

Hey guys I'm really new to both ASP.NET MVC and the MVC pattern generally. For context, I'm currently running .NET 4.0, MVC 2. I know that MCV 2 has a bunch of built in features for: validation (both client and server side, through a variety of ways) error handling (via attributes and other methods) But what should be used to retu...

High Cohesion and Concurrency - Are they conflicting interests?

I was reading Robert Martin's Clean Code and in that he mentions about the code being highly cohesive: Classes should have a small number of instance variables. Each of the methods of a class should manipulate one or more of those variables. In general the more variable a method manipulates the more cohesive that method ...

How can I clean up this code?

I want to make my code look cleaner and 'express its intent' more.. The following method is reflecting over two types and checking that if there is a property in one type, then there is a corresponding property of the same name in the other type. If there is then it sets the value of the property to the index variable. otherwise it thro...