Thursday, July 29, 2010

Making bad code good...

OK,

Had to do it..
Left that other one... Wow, horrible.

Be explicit

Example:

<cfset aThing = false>
<cfloop query="blah">
<cfif something IS true>
<cfset aThing = true>
</cfif>

<cfif NOT aThing>
sfsdf
</cfif>

Use this instead..

<cfif aThing IS true>
asdsas
</cfif>

Inline classes with lots of code, like
<td class="rowBody">

Should be set in CSS to avoid extra bandwidth usage..

More text means more noise..

Rule 1: Be clear, or be clearer..
So, if something is shorter doesn't mean its better.

Start with things that get you out of the file vs all the positive statements..
If you don't meet the conditions, get out of the file..

Look at <cfontent type="text/plain" reset="yes"> to control whitespace...
Example was outputting xml content inline without worry about including whitespace at top of file...

Mixing in <cfscript> just to "feel" more programmy, stop doing it... Harder to debug and more lines of code overall..

Stop naming variables like objX, give them names that people can follow if they need to go through code later (including yourself)

Similarly name queries with meaningful names, so it makes it easier to debug.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.