Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created October 13, 2011 13:25
Show Gist options
  • Save orangexception/1284209 to your computer and use it in GitHub Desktop.
Save orangexception/1284209 to your computer and use it in GitHub Desktop.
storeStructIntoSession
<cffunction name= "storeStructIntoSession"
output= "false"
hint= "I store a form into the session scope">
<cfargument name= "stTarget"
required= "true"
hint= "I am the target struct for storage." />
<cfargument name= "sSessionKey"
required= "false"
default= "#createUUID()#"
hint= "I am the session key for the struct." />
<cfargument name= "bIgnoreEmptyFields"
required= "false"
default= "false"
hint= "I am a toggle that will ignore empty keys." />
<cfargument name= "lsKeysToIgnore"
required= "false"
default= ""
hint= "I am a list of struct keys to ignore." />
<cfset var stCopy= duplicate( stTarget ) />
<cfset var sKey= "" />
<cfloop collection= "#stCopy#"
item= "sKey">
<cfif listFindNoCase( lsKeysToIgnore , sKey )
or ( bIgnoreEmptyFields and len( stCopy[ sKey ] ) eq 0 )>
<cfset StructDelete( stCopy , sKey ) />
</cfif>
</cfloop>
<cflock scope= "session"
type= "exclusive"
timeout= "15">
<cfset session[ sSessionKey ]= stCopy />
</cflock>
<cfreturn sSessionKey />
</cffunction>
<!--- Store Form scope into session.plansearch --->
<cfif structKeyExists( form , "fieldnames" )>
<cfset storeStructIntoSession( stTarget= form ,
sSessionKey= "plansearch" ,
bIgnoreEmptyFields= true ,
lsKeysToIgnore= "fieldnames,submit" ) />
</cfif>
@orangexception
Copy link
Author

GitHub does tabs wrong, it copies better than it looks. ;)

@jeffcoughlin
Copy link

That's why I always set my IDE to use 2 spaces instead of tabs (assuming the IDE offers it. Since 2004 I switched to Eclipse - and it offers it). When my code is viewed in other editors, it will always look the same (because every editor in the world shows tabs differently. Especially web browsers when viewing source). Yet, use two spaces and ALL editors, IDEs, web browsers, etc will always look the same.

I get flak for it often though. I don't expect others to understand because they often stick to their one IDE of choice. But when a scenario like this comes up where it needs to be viewed elsewhere or in another developer's IDE, then the pain starts to set in. One thing I don't ever use though is tabs inside tags like you have here. Line indenting is one thing, but tabs inside a tag? That just seems wrong in so many ways. Not only will it only look good in your one editor of choice, but when you bring another develop on your team who's using a different IDE, then he'll have to spend hours cleanign it up to make it readable again. I admit though that when I first started CF coding in the late 90's I did the same for a short while =.

@orangexception
Copy link
Author

I get where you're coming from. I've run a similar spacing setup before.

Like you, I have my own reasons for doing what I do. I use multiple machines and IDEs and this coding style displays fine in each. Github decided to change the tab default to 8 spaces, which is wonky no matter how you look at it.

My coding style is constantly evolving. I change my style when I find a better way, either through experimentation or reviewing code. If I think my way is better than the team standard, then I'll attempt to show them why and update the standard.

If the team standard was different from the default of 4 spaces for 1 tab, then I would adapt to fit for team code.

I figure if a team member wants to change the style, then they're welcome to do so. Some IDEs allow you to change formatting in a button press. Otherwise, you can do a simple find and replacements to change the spacing. The whole process shouldn't take more than a few minutes. (I have some replacement scripts if you're interested.) If you're coding differently from the team standard, then you get to live with the consequences of your choice.

I'll probably do a whole post on my coding style, but that's the gist of it (couldn't resist).

@jeffcoughlin
Copy link

jeffcoughlin commented Nov 14, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment