Sunday, August 9, 2009

Robot Coders

In most trades people do what they are told, it gets done, and life goes on. Development requires you think into the future to prevent issues, which may bring a developer to challenging the validity of the task. Challenging a task could potentially bring up new ideas or issues. I am not saying challenge every thing that is assign to you, but do a quick check against the current state of the app. A quick check could create a new module or even a product. It could also bring up trickle down issues that may occur from bringing in a new change or feature.

From what I've seen so far,in the 2 years of coding, is that some developers are mindless coders. They are like robots whom take input and return results. While management loves this, development hates it. The problem with coding this way is you get crap code that only serves a one-off purpose from either a quick decision or sales promise and harms the purpose of a feature or even the app. I just think things should be thought through a little more before they are coded up, and it is the responsibility of the coder , as a last resort, to take care of this. I am not asking for a design meeting, but 5 to 10 minutes of quick thinking or maybe a peer's opinion may bring something important up that will save time and money in the long run.

A few things I do before coding something up are:
1. What parts will be affected?
2. Will this change the current purpose of the code in a way that is not desired or maybe interpreted incorrectly?
3. How much code do I need to change?
4. Do the database relationships support what I am going to do?
5. Do I have the time to make the changes without throwing some spaghetti code together?
6. Will my changes effect/prevent someone else's ability to work?
7. Do I need a hand with the design or amount of this task?
8. Are the changes worth my time right now or are there bigger fish to fry first?

These are just a few things that go through my mind before I begin a task. I think the robot coders should become human again, by learning to think outside the box or for themselves and not by an outside entity. What goes though your guy's mind before you begin coding?

Monday, June 15, 2009

Select into from ColdFusion query object

So I got a question from a friend of mine who had a query returned in ColdFusion and wanted to do a "select into" with the query object. He found out how to do it one statement. Check it out.


<cfquery datasouce="ds">
SELECT COLUMN_1,COLUMN_2,COLUMN_3
INTO DATABASE_TABLE
FROM QUERYOBJECT.THEQUERY
</cfquery>

Thursday, May 21, 2009

Default on bit column in sql.

alter table tablename
add constraint DF_tablename_columnname default ((0)) for columnname

Monday, May 18, 2009

Merging cfdocuments into pdf without creating a file

So I was working with a dms and wanted to try not writing and reading pdf files but instead using the cf and db to display the data. I struggled with invoking cfpdfparam source attribute on cfpdf action="merge" because it doesn't take straight up binary, which is what cfdocument is returning. So I created a pointer variable and passed that in and it accepted. Kinda wierd it wouldn't accept it but oh well. Check it out.


<!--- get the pages --->
<cfset pages = beans.docService.getPagesByVersionID(versionID=versionID)/>

<!--- create array to hold cfdocuments --->
<cfset documents = []/>

<!--- loop pages and create cfdocuments --->
<cfloop query="pages">

<cfdocument name="pdf_name" format="pdf" pageheight="#pages.height#" pagewidth="#pages.width#" pagetype="#pages.doc_page_type_Name#" orientation="pages.document_orientation_type_name#">

<!--- get the page layout --->
<cfset layout[id] = beans.docService.getLayoutByID(pages.layout_id) />

<!--- get xmltransform--->
<cfsilent>
<cfset html[id] = xmltransform(xml,layout[id].xslt) />
</cfsilent>

<!--- set margins --->
<cfdocumentsection
marginbottom="#pages.bottom_margin#"
marginleft="#pages.left_margin#"
marginright="#pages.right_margin#"
margintop="#pages.top_margin#">

<!--- output data --->
<cfoutput>#html[id]#</cfoutput>

</cfdocumentsection>

</cfdocument>

<!--- add binary cfdocument to the --->
<cfset arrayappend(documents,pdf_name) />

</cfloop>


<!--- merge cfdocuments into 1 pdf. this will return some binary --->
<cfpdf action="merge" name="final">

<cfloop from="1" to="#arraylen(documents)#" index="i">

<!--- set pointer for cfpdfparam source, this part took me forever to figure out because the source attribute is looking for a pointer variable. you can't just pass in the binary --->
<cfset pointer = documents[i]/>

<cfpdfparam source="pointer">

</cfloop>

</cfpdf>

<!--- output the pdf --->
<cfcontent type="application/pdf" variable="#tobinary(final)#" reset="No" >

Wednesday, May 13, 2009

The litte things

As I logged into my bank accounts online I realized how much of the little things are missing from a page. Details such as label tags on radio and checkboxes, titles on links, and directions steps in a wizard are just to name a few. When working with presentation, people remember every little detail. So remember to think of the little things.

Wednesday, April 22, 2009

Coldfusion writing simple xslt

I think it would be kinda cool to not have to write xslt as much any more, so a coworker and I created some helper functions to handle tables for us. So instead of writing xslt to create a table tag where we can pump xml into we created coldfusion functions with which can shoot args and write the xslt for us.

Here we call a beginTable() with which we can give it attributes.

<cffunction name="beginTable" access="public" returntype="string" output="false" >

<cfset var local = {} />

<cfset arguments = getArguments(arguments) />

<cfsavecontent variable="local.string">
<cfoutput>
<xsl:call-template name="beginTable">

#renderXSLTParams(argumentCollection=arguments)#

</xsl:call-template>
</cfoutput>
</cfsavecontent>

<cfreturn local.string>

</cffunction>

First we can getArguments which handles our common attributes of the tag we are trying to create. getArguments() can be used to set out defaults but of simplicity we just loop a list of common attributes.

<cffunction name="getArguments" access="public" output="false" returntype="struct">
<cfargument name="args" required="true" />

<cfset var local = {} />

<cfset local.args = arguments.args />

<cfloop list="class,style,title,alt,id,height,width,colspan,cellspacing,cellpadding,align,border,src,value" index="local.i">
<cfset local.args[lcase(local.i)] = getKey(lcase(local.i),local.args,"#local.i#") />
</cfloop>

<cfreturn local.args />

</cffunction>

Second, we write the xlst beginTable template and create the xslt params using renderXSLTParams.

<cffunction name="renderXSLTParams" access="public" returntype="string" output="false" >

<cfset var local = {} />
<cfset var i = "" />

<cfsavecontent variable="local.string">
<cfoutput>
<cfloop collection="#arguments#" item="i">
<xsl:with-param name="#lcase(i)#">
<cfif (FindNoCase('%',arguments[i],1) or FindNoCase('px',arguments[i],1) )>
<xsl:text>#arguments[i]#
<cfelse>
<xsl:value-of select="#lcase(arguments[i])#"/>
</cfif>
</xsl:with-param>
</cfloop>
</cfoutput>
</cfsavecontent>

<cfreturn local.string/>

</cffunction>

That takes care of creating the xslt snippet for the begin table tag, now we have to load the tag at the bottom of the xslt so we can call the template and invoke the params. To do this we output the load function which contains all our template snippets.

<cffunction name="load" access="public" output="false" returntype="string" >

<cfset var local = {}/>

<cfsavecontent variable="local.string">
<cfoutput>
<xsl:template name="beginTable">
#getTemplateParams()#
<xsl:text disable-output-escaping="yes"><</xsl:text>table
#getXSLTParams()#
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:template>

<xsl:template name="endTable">
<xsl:text disable-output-escaping="yes"><</xsl:text>/table
</xsl:template>

</cfoutput>
</cfsavecontent>

<cfreturn local.string/>

</cffunction>

In the load function we call getTemplateParams() to create our template params.


<cffunction name="getTemplateParams" access="public" returntype="string" output="false" >

<cfset var local = {}/>
<cfset var i = ""/>

<cfset arguments = getArguments(arguments)/>

<cfsavecontent variable="local.string">
<cfoutput>

<cfloop collection="#arguments#" item="i">

<xsl:param name="#lcase(i)#"/>

</cfloop>

</cfoutput>

</cfsavecontent>

<cfreturn local.string/>

</cffunction>

Next we call getXSLTParams(). to actually invoke the xslt params

<cffunction name="getXSLTParams" access="public" returntype="string" output="false" >

<cfset var local = {}/>
<cfset var i = ""/>

<cfset arguments = getArguments(arguments)/>

<cfsavecontent variable="local.string">
<cfoutput>

<cfloop collection="#arguments#" item="i">
<xsl:if test="$#lcase(i)# != '' ">
#lcase(i)# ='
</xsl:if>
</cfloop>

</cfoutput>
</cfsavecontent>

<cfreturn local.string/>

</cffunction>

And that should do it.

Thursday, April 9, 2009

Accessing a queries row by row number

query.column[rownumber]

I was asked to do a task which involved a select box with arrows on each side of it. The arrows were to be used for the next and previous record in the select box when the page first rendered. For awhile I have wanted to use a query row number to access data directly and now get the chance to.

I used the current selected id and loop the query just got the above and below row from the current row by accessing the query struct.

Example:


<cfset the_id="124"/>
<cfset above_id=""/>
<cfset below_id=""/>

<cfloop query="the_query">

<cfif the_id = the_query.id>

<cfset above_id= the_query.id[currentrow + 1] />

<cfset below_id= the_query.id[currentrow - 1] />
<cfbreak />
</cfif>
</cfloop>