SlideShare a Scribd company logo
CFWheels
Pragmatic, Beautiful code
Indy Nagpal
Straker Software
Melbourne, November 2010
A bit about me
•  CTO, Straker Software, New Zealand
•  Been doing CF (and Flex) for a while
•  Cloud-based CF Using Railo
•  In love with Ruby (the language) & Rails
– Was in love with Groovy (still am, I think)
•  nagpals.com/blog
Rapid ≠ Agile
Agile
•  Early, continuous delivery of software
•  Welcome changing requirements
•  Deliver working software frequently
•  Working software = progress
•  Technical excellence and good design
•  Simplicity is essential – work not done
“There comes a time in the history of
every project when it becomes
necessary to shoot the engineers and
begin production.”
Need
•  Quickly build and deploy database-driven
web apps
•  Rapid iterations in a testable fashion
•  Easy for multiple developers to understand
•  Working app is more important than
configuring the app
Search…
•  Tried lots of frameworks/methodologies
•  Ruby on Rails addressed most issues
•  Learn another language and framework
•  Defeats the whole purpose
•  Enter, CFWheels…
What is CFWheels
•  Framework inspired by Ruby on Rails
•  Simple organization system
•  Suited for typical, database-driven web
applications
•  A couple of years’ old – fairly mature
Convention over configuration
•  Possibly the single most important thing
•  Mostly convention, minor configuration
•  Easy to
– turn on
– tune in
– drop out
Directory structure
•  webroot
– models	
– controllers	
– views	
– images	
– javascripts	
– stylesheets	
– plugins	
– tests	
– events	
– config
Intuitive Code Structure
•  View
–  Responsible for display and user interaction
–  Receive data from controller
•  Controller
–  Process requests from view
–  Get/process data from model
–  Make data available to the view
•  Model
–  Interacts with the database layer
–  Responsible for validation
–  Other methods to process/message data
Convention - URLs
•  URLs mapped to controllers/models/views
http://blog/posts/edit/1	
Controller: Posts
Model: Post
Action: Edit
Key: 1
View – http://blog/posts/
/views/posts/index.cfm	
<cfparam name="posts">	
<ul>	
<cfoutput query="posts">	
	<li>	
	 	#linkTo( 	text 	= "#posts.title#", 	
	 	 	 	action	= "edit", 	
	 	 	 	key 	= post.id, 	
	 	 	 	title 	= "Edit #posts.name#"	
	 	 	 	)#	
	</li>	
</cfoutput>	
</ul>
Controller – http://blog/posts/
/controllers/Posts.cfc	
<cfcomponent extends="Controller">	
<cfscript>	
	function index(){	
	 	posts = model("post").findAll(order="createdAt")	
	}	
</cfscript>	
</cfcomponent
Model – http://blog/posts/
/models/Post.cfc	
<cfcomponent extends="Model">	
<cfscript>	
	function init(){	
	 	belongsTo("author")	
	 	hasMany("comments")	
	 		
	 	validatesLengthOf( 	properties 	= 	"title",	
	 	 	 	 	minimum 	= 	10,	
	 	 	 	 	maximum 	= 	255)	
	}	
</cfscript>	
</cfcomponent>
Convention – Files & Database
•  Place in appropriate folders – MVC
•  Plural database names, singular model
names
– DB Table: posts	
– Model: Post.cfc	
•  Database fields: id, createdat, updatedat
Built-in ORM
•  Simple and elegant
•  All major databases supported
•  Almost no setup required – baked in
•  CRUD instantly available via models/plugin
•  Finding data using “finders”
–  findOne(), findAll(), findByKey()…
Associations
models/Post.cfc	
<cfcomponent extends="Model">

<cfscript>	
	 	function init(){	
	 	 	belongsTo("author")	
	 	}	
</cfscript>

</cfcomponent>	
models/Author.cfc	
<cfcomponent extends="Model">

<cfscript>	
	 	function init(){	
	 	 	hasMany("posts")	
	 	}	
</cfscript>

</cfcomponent>	
<cfscript>	
	posts 	= model("post").findAll(include="author")	
	author 	= model("author").findOneByKey(key=params.key,include="posts")	
</cfscript>
Dynamic Finders
•  Dynamic finders are magical
model("user").findOne(where="username='bob' and password='pass'")	
rewritten as
	model("user").findOneByUsernameAndPassword("bob,pass”)
URLs and Routing
•  Beautiful URLs
–  http://blog/a-good-url	
•  Powerful routing mechanism
	<cfset addRoute( 	name 	 	= "showPost", 

	 	 	pattern	 	= "/[key]”,

	 	 	controller 	= "Posts",

	 	 	action	 	= "show")>
•  Can be turned REST-full
Multiple response formats
•  http://blog/posts	
•  http://blog/posts.xml	
•  http://blog/posts.json	
•  http://blog/posts.csv	
•  http://blog/posts.pdf
Common tasks done
•  Adding timestamps
•  Flashing messages
•  Pagination
•  Sending multi-part emails
•  Redirecting users
Lots of helper functions
•  Views
selectBox()	
linkTo()	
timeAgoInWords()	
paginationLinks()	
titleize()	
pluralize()	
•  Model
validatePresenceOf()	
findAll()	
findOneByKey()	
afterSave()	
•  Controller
flash()	
isGet()	
sendMail()
Plugins
•  Neat architecture to add/override
functionality
•  Extremely useful
– Scaffold –generate CRUD application
– DBMigrate – Add/edit database structure
– Remote Form Helpers – Ajax with forms
– Localizer – Localizing an application
Baked in testing
•  Ships with RocketUnit
<cfcomponent extends="tests.Test">	
<cfscript>	
	function test_1_get_timezones(){	
	 	qTimezone 	= model("Timezone").getTimezones()	
	 	assert("isQuery(qTimezone) ")	
	 	assert("qTimezone.recordcount eq 56")	
	}	
	 	 		
</cfscript>	
</cfcomponent>
Environments
•  Different setup for applications based on
stages of development
– Design, Development, Production, Testing,
Maintenance
•  Differ in terms of caching, error-handling
•  Switch environments via config/url
Docs/Support
•  Very helpful docs at cfwheels.org
•  Active and supportive mailing list
•  Quite a few screencasts
•  Direct knowledge transfer from Ruby on
Rails books/docs (e.g., Head First Rails)
•  Bunch of blogs
IDE Support
•  Eclipse, CFBuilder
– Syntax Dictionary
•  Textmate
– Bundle
•  Coda
– Lacking, but works by adding Clips
Beauty
•  Simple code organization and flow
•  Easy to understand code – eyeballing code
•  Common tasks done with minimal code
•  Pretty URLs
•  Almost zero configuration, with power to
configure as much as needed
Pragmatic
•  Focus on simple code that solves issues
•  Trades pure OO for simplicity and structure
•  Easy to not use the framework if needed
•  Common web application problems already
solved – why reinvent the wheel(s)!
Wrap up
•  Evaluate if you need a ‘framework’
•  Learn URL rewrites (Apache, IIS)
•  Dabble with Ruby on Rails
•  cfscript = succinct code
•  Worth trying out just to see how problems
can be solved in a different manner
Thank you
Questions?
indy@nagpals.com	
nagpals.com/blog

More Related Content

PPTX
Command box, Package Manager, Automation, REPL
PPTX
Microservices with Apache Camel, Docker and Fabric8 v2
PPTX
Lessons from the Trenches - Building Enterprise Applications with RavenDB
PDF
Ozone-Wayland Support in Chromium (GENIVI 13th All Member Meeting & AMM Open ...
PPTX
Let's server your Data
PDF
Adobe AEM for Business Heads
PDF
Spicing up JMX with Jolokia (Devoxx 2014)
PDF
Social Connections 2015 CrossWorlds and Domino
Command box, Package Manager, Automation, REPL
Microservices with Apache Camel, Docker and Fabric8 v2
Lessons from the Trenches - Building Enterprise Applications with RavenDB
Ozone-Wayland Support in Chromium (GENIVI 13th All Member Meeting & AMM Open ...
Let's server your Data
Adobe AEM for Business Heads
Spicing up JMX with Jolokia (Devoxx 2014)
Social Connections 2015 CrossWorlds and Domino

What's hot (20)

PPTX
RavenDB 3.5
PPTX
RavenDB 4.0
PDF
Infinum Android Talks #09 - DBFlow ORM
PDF
Innovating faster with SBT, Continuous Delivery, and LXC
PPT
Real World Rails Deployment
PDF
Simplify integrations-final-pdf
KEY
Why ruby and rails
PDF
4 JVM Web Frameworks
PPTX
Automating JavaScript testing with Jasmine and Perl
PDF
High Performance Systems in Go - GopherCon 2014
PPTX
Zapping ever faster: how Zap sped up by two orders of magnitude using RavenDB
PDF
About Caching
PDF
MongoDB Days UK: Using MongoDB to Build a Fast and Scalable Content Repositor...
PPTX
Don't worry with bower
PPTX
Zend Framwork presentation
PPTX
Javascript on Server-Side
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
PPTX
PDF
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
PPTX
Hands-on Performance Tuning Lab - Devoxx Poland
RavenDB 3.5
RavenDB 4.0
Infinum Android Talks #09 - DBFlow ORM
Innovating faster with SBT, Continuous Delivery, and LXC
Real World Rails Deployment
Simplify integrations-final-pdf
Why ruby and rails
4 JVM Web Frameworks
Automating JavaScript testing with Jasmine and Perl
High Performance Systems in Go - GopherCon 2014
Zapping ever faster: how Zap sped up by two orders of magnitude using RavenDB
About Caching
MongoDB Days UK: Using MongoDB to Build a Fast and Scalable Content Repositor...
Don't worry with bower
Zend Framwork presentation
Javascript on Server-Side
DrupalCampLA 2014 - Drupal backend performance and scalability
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
Hands-on Performance Tuning Lab - Devoxx Poland
Ad

Viewers also liked (6)

PDF
Testing For Success
KEY
Make It Cooler: Using Decentralized Version Control
KEY
Using NoSQL MongoDB with ColdFusion
PDF
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
PDF
CommandBox : Free CFML
PDF
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Testing For Success
Make It Cooler: Using Decentralized Version Control
Using NoSQL MongoDB with ColdFusion
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
CommandBox : Free CFML
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Ad

Similar to CFWheels - Pragmatic, Beautiful Code (20)

PDF
Intro to ColdBox MVC at Japan CFUG
PPTX
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
PPTX
AngularJS One Day Workshop
PDF
Staging Drupal 8 31 09 1 3
PPTX
FlexDeploy Product Technical Overview
PPT
Integrating AngularJS with Drupal 7
PPTX
Asp.net mvc presentation by Nitin Sawant
PPTX
MVC 6 - the new unified Web programming model
PDF
Rapid application development with spring roo j-fall 2010 - baris dere
PDF
The future of web development write once, run everywhere with angular js an...
PPTX
The future of web development write once, run everywhere with angular.js and ...
PPTX
Web Techdfasvfsvgsfgnolofgdfggy Unit I.pptx
PDF
Agile Secure Cloud Application Development Management
PDF
[Struyf] Automate Your Tasks With Azure Functions
PPTX
Structured Functional Automated Web Service Testing
PDF
Introduction to Flask Micro Framework
PDF
symfony_from_scratch
PDF
symfony_from_scratch
PPTX
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
PDF
Codeigniter
Intro to ColdBox MVC at Japan CFUG
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
AngularJS One Day Workshop
Staging Drupal 8 31 09 1 3
FlexDeploy Product Technical Overview
Integrating AngularJS with Drupal 7
Asp.net mvc presentation by Nitin Sawant
MVC 6 - the new unified Web programming model
Rapid application development with spring roo j-fall 2010 - baris dere
The future of web development write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular.js and ...
Web Techdfasvfsvgsfgnolofgdfggy Unit I.pptx
Agile Secure Cloud Application Development Management
[Struyf] Automate Your Tasks With Azure Functions
Structured Functional Automated Web Service Testing
Introduction to Flask Micro Framework
symfony_from_scratch
symfony_from_scratch
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Codeigniter

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Understanding_Digital_Forensics_Presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology

CFWheels - Pragmatic, Beautiful Code

  • 1. CFWheels Pragmatic, Beautiful code Indy Nagpal Straker Software Melbourne, November 2010
  • 2. A bit about me •  CTO, Straker Software, New Zealand •  Been doing CF (and Flex) for a while •  Cloud-based CF Using Railo •  In love with Ruby (the language) & Rails – Was in love with Groovy (still am, I think) •  nagpals.com/blog
  • 4. Agile •  Early, continuous delivery of software •  Welcome changing requirements •  Deliver working software frequently •  Working software = progress •  Technical excellence and good design •  Simplicity is essential – work not done
  • 5. “There comes a time in the history of every project when it becomes necessary to shoot the engineers and begin production.”
  • 6. Need •  Quickly build and deploy database-driven web apps •  Rapid iterations in a testable fashion •  Easy for multiple developers to understand •  Working app is more important than configuring the app
  • 7. Search… •  Tried lots of frameworks/methodologies •  Ruby on Rails addressed most issues •  Learn another language and framework •  Defeats the whole purpose •  Enter, CFWheels…
  • 8. What is CFWheels •  Framework inspired by Ruby on Rails •  Simple organization system •  Suited for typical, database-driven web applications •  A couple of years’ old – fairly mature
  • 9. Convention over configuration •  Possibly the single most important thing •  Mostly convention, minor configuration •  Easy to – turn on – tune in – drop out
  • 11. Intuitive Code Structure •  View –  Responsible for display and user interaction –  Receive data from controller •  Controller –  Process requests from view –  Get/process data from model –  Make data available to the view •  Model –  Interacts with the database layer –  Responsible for validation –  Other methods to process/message data
  • 12. Convention - URLs •  URLs mapped to controllers/models/views http://blog/posts/edit/1 Controller: Posts Model: Post Action: Edit Key: 1
  • 13. View – http://blog/posts/ /views/posts/index.cfm <cfparam name="posts"> <ul> <cfoutput query="posts"> <li> #linkTo( text = "#posts.title#", action = "edit", key = post.id, title = "Edit #posts.name#" )# </li> </cfoutput> </ul>
  • 14. Controller – http://blog/posts/ /controllers/Posts.cfc <cfcomponent extends="Controller"> <cfscript> function index(){ posts = model("post").findAll(order="createdAt") } </cfscript> </cfcomponent
  • 15. Model – http://blog/posts/ /models/Post.cfc <cfcomponent extends="Model"> <cfscript> function init(){ belongsTo("author") hasMany("comments") validatesLengthOf( properties = "title", minimum = 10, maximum = 255) } </cfscript> </cfcomponent>
  • 16. Convention – Files & Database •  Place in appropriate folders – MVC •  Plural database names, singular model names – DB Table: posts – Model: Post.cfc •  Database fields: id, createdat, updatedat
  • 17. Built-in ORM •  Simple and elegant •  All major databases supported •  Almost no setup required – baked in •  CRUD instantly available via models/plugin •  Finding data using “finders” –  findOne(), findAll(), findByKey()…
  • 18. Associations models/Post.cfc <cfcomponent extends="Model">
 <cfscript> function init(){ belongsTo("author") } </cfscript>
 </cfcomponent> models/Author.cfc <cfcomponent extends="Model">
 <cfscript> function init(){ hasMany("posts") } </cfscript>
 </cfcomponent> <cfscript> posts = model("post").findAll(include="author") author = model("author").findOneByKey(key=params.key,include="posts") </cfscript>
  • 19. Dynamic Finders •  Dynamic finders are magical model("user").findOne(where="username='bob' and password='pass'") rewritten as model("user").findOneByUsernameAndPassword("bob,pass”)
  • 20. URLs and Routing •  Beautiful URLs –  http://blog/a-good-url •  Powerful routing mechanism <cfset addRoute( name = "showPost", 
 pattern = "/[key]”,
 controller = "Posts",
 action = "show")> •  Can be turned REST-full
  • 21. Multiple response formats •  http://blog/posts •  http://blog/posts.xml •  http://blog/posts.json •  http://blog/posts.csv •  http://blog/posts.pdf
  • 22. Common tasks done •  Adding timestamps •  Flashing messages •  Pagination •  Sending multi-part emails •  Redirecting users
  • 23. Lots of helper functions •  Views selectBox() linkTo() timeAgoInWords() paginationLinks() titleize() pluralize() •  Model validatePresenceOf() findAll() findOneByKey() afterSave() •  Controller flash() isGet() sendMail()
  • 24. Plugins •  Neat architecture to add/override functionality •  Extremely useful – Scaffold –generate CRUD application – DBMigrate – Add/edit database structure – Remote Form Helpers – Ajax with forms – Localizer – Localizing an application
  • 25. Baked in testing •  Ships with RocketUnit <cfcomponent extends="tests.Test"> <cfscript> function test_1_get_timezones(){ qTimezone = model("Timezone").getTimezones() assert("isQuery(qTimezone) ") assert("qTimezone.recordcount eq 56") } </cfscript> </cfcomponent>
  • 26. Environments •  Different setup for applications based on stages of development – Design, Development, Production, Testing, Maintenance •  Differ in terms of caching, error-handling •  Switch environments via config/url
  • 27. Docs/Support •  Very helpful docs at cfwheels.org •  Active and supportive mailing list •  Quite a few screencasts •  Direct knowledge transfer from Ruby on Rails books/docs (e.g., Head First Rails) •  Bunch of blogs
  • 28. IDE Support •  Eclipse, CFBuilder – Syntax Dictionary •  Textmate – Bundle •  Coda – Lacking, but works by adding Clips
  • 29. Beauty •  Simple code organization and flow •  Easy to understand code – eyeballing code •  Common tasks done with minimal code •  Pretty URLs •  Almost zero configuration, with power to configure as much as needed
  • 30. Pragmatic •  Focus on simple code that solves issues •  Trades pure OO for simplicity and structure •  Easy to not use the framework if needed •  Common web application problems already solved – why reinvent the wheel(s)!
  • 31. Wrap up •  Evaluate if you need a ‘framework’ •  Learn URL rewrites (Apache, IIS) •  Dabble with Ruby on Rails •  cfscript = succinct code •  Worth trying out just to see how problems can be solved in a different manner