Search

Subscribe

Enter your email address to subscribe to this blog.

Recent Comments

Intro to Spring Security Core for Grails
Eric Pierce said: Thanks for these screencasts, Dan! You made it crazy simple to get up and running w/security core h... [More]

Removing duplicates from an array of objects
Arvind said: Great tip, can't thank you enough for this. [More]

Intro to Spring Security Core for Grails
Santosh said: Thanks much for putting up these screencasts. As the others here I'm a beginner and I've been having... [More]

Grails Spring Security Plugin - Logout postOnly setting
eriihine said: I still had some issues with this one. It seems that the href link is always generating a GET method... [More]

Intro to Spring Security Core for Grails
Dan Vega said: Just a heads up but I decided to write up a quick post on your question just in case it trips up any... [More]

Hooking into Git with Rick Osborne

If you didn't know the Central Florida Web Developers User Group meeting is tonight. Rick Osborne will be presenting Hooking into Git. What you may not know is that you don't have to be in Florida to attend the user group meeting. They do a great job of putting these presentations online. Click on the link below and RSVP for the meeting now!

http://www.meetup.com/florida-web-developers/events/20352661

 
 

Learn a new language over the holidays

I am off in about an hour until the new year and I am pretty excited to have a nice long break. If you are looking to pick up another language over the Holidays I would suggest looking at 2 languages. Groovy/Grails if you want to stay in a similar environment and python because well it just seems cool and a buddy of mine is a python developer and swears by it. Luck for you Grails 1.2 was just released. I did a quick scan through the new features and found something that I thought was pretty cool. GORM now supports defining named queries in a domain class. For example, given a domain class like this: This allows you to do:

I hope all of you have a wonderful holiday and if you have some extra time fill your brain with some knowledge!

 
 

There are no final decisions!

Anyone who has read The Pragmatic Programmer has heard this before and I know I keep discussing topics from the book but I just can not get enough. If you have been around the software development world for even a short period of time there is one constant lesson you have learned, and at some point probably the hard way. It boils down to one simple sentence. In software development there is one constant, CHANGE. This will hold true from projects that take a whole development team months to complete down to simple applications that take a single developer weeks to complete.

If we could just see this future this would never be a problem ,unfortunately this is the real world. If we can not see the future how are we to prepare. First you can prepare yourself by realizing that change will happen during the application development cycle. I try to remember that customers needs change so it is always best to anticipate these changes and try to bring them to the customer during the planning phase. The analysis of a project is the most important phase and way out of the scope of this post, just understand it is more important then your coding skills, however great they may be.

This is one part of application development I need to get better at. Right from my new handle book I would like to quote something that sums everything I have been talking about quite nice.

The mistake lies in assuming that any decision is cast in stone--and in not preparing for the contingencies that might arise. Instead of carving decisions in stone, think of them more as being written in the sand at the beach. A big wave can come along and wipe them out at any time.

There Are No Final Decisions

 
 

Avoid Global Data

I have just started to read a new book titled The pragmatic programmer. I am quickly realizing why everyone has dubbed this book a must have for all programmers. I am only into the 2nd chapter but I already found something I would like to share with you. This may seem like a no brainer to most of you but to some beginners this is a very important lesson to building a reusable & scalable system.

So how and why would we avoid global data. Lets first examine what The Pragmatic programmer would tell us about global data.

Every time your code references global data, it ties itself into the other component that share that data. In general your code is easier to understand and maintain if you explicitly pass any required context into your modules. In object oriented applications, context is often passed as parameters to objects constructors.
Basically what this tells us is that it is poor design to reference global data in our component when we can create a more maintainable & reusable component by passing that data as a parameter. We will look at some code below to see how this applies in our world.

Lets say for example that in our Application component we define some global data and place it into our application scope like so.

view plain print about
1<cfset application.dsn = "myDSN">
2<cfset application.dbuser = "user">
3<cfset application.dbpass = "pass">

This is code that we all have written at one time (or something similar) and there is nothing wrong with this code. Here is where our mistake is made. Lets say we create an Employee component and in the component we need to access our database. We need to know these parameters so beginners may have the desire to write the following code.

view plain print about
1<cfcomponent>
2    <cffunction name="getAll" access="public" returntype="query">
3        <cfset var local = "">
4        <cfquery name="local" datasource="#application.dsn#">
5        SELECT * FROM Employee
6        </cfquery>
7        <cfreturn local>
8    </cffunction>
9</cfcomponent>

So your thinking to yourself what is wrong with that. It is maintainable because if our dsn changes for some reason we only have to change it in one place. You would be right but it also is not very reusable. The best answer is to stay away from global data and pass it into your component as an instance parameter. So how do we do that, simple lets look at the answer.

view plain print about
1<cfcomponent>
2    
3    <cfset variables.dsn = "">
4    
5    <cffunction name="init" access="public" returntype="Employee">
6        <cfargument name="dsn" type="string" required="true">
7        <cfset variables.dsn = arguments.dsn>
8        <cfreturn this>
9    </cffunction>
10    <cffunction name="getAll" access="public" returntype="query">
11        <cfset var local = "">
12        <cfquery name="local" datasource="#variables.dsn#">
13        SELECT * FROM Employee
14        </cfquery>
15        <cfreturn local>
16    </cffunction>
17    
18</cfcomponent>

This code makes our component maintainable and reusable. Now we could pass our global data into the component. The moral of the story kids, avoid global data in your components.

view plain print about
1<cfset empObj = createObject("component","employee").init(application.dsn)>
2<cfset employees = empObj.getAll()>


 
 

My 3 New Books & Concept over Code

Well besides being very busy lately I got 3 new books sent to me. Most of you have read them and I am learning quickly that two of these are must have reads for any programmer.

  • Head First Design Patterns
  • The Pragmatic Programmer
  • Pragmatic version control using SubVersion
I have started to read Head First design patterns in conjunction with the book I am already reading Object Oriented Analysis and design. I am only 2+ chapters deep in the Design patterns book but for the first time In my short programming career I am learning that the code is secondary to the concept. For all of you noobs out there try to understand what I just said. Learn why you are doing something before the code . I think that is very hard to understand starting out but very very important. I am really excited to get all of these books in and promise to keep you all up to date in my journey. I can already tell the Strategy pattern will play a big role in my development going forward and hope to share my thoughts on that shortly.

 
 

More Entries