Thursday, August 05, 2004

Site Search Bookmarklet

In the last couple of days, I've been playing with Bookmarklets, as ways to enhance my browsing experience.

One of the cool things, I have found is ways to search for things on your current page, and present that in IE's sidebar.

So that instead of replacing the current page, you can use put content in the sidebar.

Site Search Bookmarklet - Just drag to your links toolbar.

The way this works, you select some text on a webpage, until it is highlighted, then click on this bookmarklet on your links toolbar, and google will search that site for that highlighted text.
Neat, huh?

My next project is to detect an rss feed on a webpage, and display the transformed version of that rss/xml feed in the ie side panel...

Tell me what you think.
Have fun!

Applying CF Best Practices - joe rinehart on CF and more

This is my attempt to show how to apply Joe Rinehart's Best Practices list...

1. Never trust user input

I always have my own version of a local variable name, that can not be overwritten without my consent. This is both good for security and data type validation, but makes it easy for form displays.

Because when I create my forms to edit/add content, I always create the edit form, with cfoutput surrounding my local variables.

But when you use cfparam to pre-define your local variables, then it really makes it easy to use the same code from editing content to adding content.

2. cfqueryparam or caching and data type validation

The benefits vary somewhat based on what database you are using. In Oracle, cfqueryparam also allows you to take advantage of Bind Variables, to improve performance.

Using it with SQL Server just allows you to use it's datatype validation methods.

And you can use cfqueryparam in where, select, anywhere where there is dynmamic variables affecting the sql code.

Remember cfqueryparam isn't needed if you the dynamic part isn't being controlled or sent by a user. Although it is a good practice.

You have to evaluate which caching method benefits you most, based on whether it's frequentally changing data, or frequentally needed data.

3. Coding for Portability

This is in general a good idea, to use variables, to hold data that changes based on what server you are on, and store them in your application scope, in the application.cfm file.

It does get to be a pain to have change hundreds of files, if your datasource or folder structure changes.

4. Code Formatting

Please use the same syntax of commenting, like some older coders put their comments to the right of the commands, and some above the commands. Stick to one style.

This also includes indenting, which is my favorite easy way of following the logic flow of an application...

5. Use existing public code

Well there are a lot of resources out the of udf's, custom tags, all kinds of ways to do a specific task.

Try looking around, and seeing if a free piece of code can do what you want, before you try creating from scratch.

6. Variable Scoping

I've written enough to explain the importance of variable scoping. It really comes down to being careful to make sure the variables hold the data you want them to.

I always use cfparam to create a local variable, which then i can logically pass url, query, form, file, cookie, client data.

The key is control what data gets into what variable.

8. Performance Matters

CFMX has really advanced it's debugging information, it shows allt he includes that your application calls, and makes it easy to identify bottlenecks.

If an include takes more than 250 mx, then it bolds/reddens that debug info, to show you to be aware of this includes performance issues.

Take care of your queries, logic flow, keep an eye how much processing power it takes to do your job.


In conclusion.

Best Practices are always evolving, because all of us want to learn from our and other's mistakes so that we can do a professional job.

Because none of us want to go back to a project we thought we completed, only to find out it crashed the site, or didn't work, or had x number of errors.

The more thorough and precise in our coding, the better we will get in the long haul..

What best practices do you use, that are not in the list? What practices do you think make sense or no sense?

Please comment and let us know!


Wednesday, August 04, 2004

Stored procedures applied per situation

Stored procedures are bad, m'kay?

It really depends on your situation, in terms of stored procedures vs no stored procedures.

1. Is this for an intranet, extranet or internet site?
2. How many different records are you planning to pump thru the procedure?
3. How many different logic flows, looping would you need?

I do agree that stored procedures aren't the solution for everything, and perhaps there was this drive towards stored procedures as a solution for bad coldfusion/sql programming, to help produce great results in reasonable performance.

It just depends on your needs.

If it's a 1-time query, then you don't need to save it as a stored procedure, unless for example, it's for a monthly/yearly report, in that case you would save it, so that you won't have to redo it, the next time you need it.

The real issue is whether you pay attention to how your queries affect both the load on coldfusion and sql server, but how it affects the load time of your visitors/users.

Sidenote: There seems to be two major opinionated camps, those that think sticking to best practices and reasonable coding standards is a great idea, and those that think it's not that important or even a waste of time.

I know that I and a few other bloggers, really recycle those standards and best practices and standards. And I'll acknowledge discussing them isn't hip or cool, but it's really out of a desire to encourage everyone to perfect their craft.

Because when you release crappy code, that isn't documented, or crashes after it's taken from Access to SQL Server, or any number of the experiences I and thousands of coders have experienced in cleaning up after other people's work.

It's just a pain in the butt, it makes you look bad, and it makes us waste time trying to do the job you should have done...

Maybe we should start sharing some of our horror stories... - joe rinehart on CF and more - joe rinehart on CF and more

A very nice re-introduction of Coldfusion's Forgotten Best Practices.

I know it's one of my favorite topics, to hone into our cultural mindset the importance, of sticking to the best coding/programming practices.

So that we can demonstrate that we are great coders, and that coldfusion is a great platform.

How about this, who are your favorite coders, or favorite applications you like to code or, some website program you did, that you are proud of?

Let's share our glory moments while we can!

Tuesday, August 03, 2004 - Blog - Blog

This is a great starting point, but I feel sometimes, that it's not really a logical argument that is being presented back and forth.

After all, once someone is sold on a particular technology, it's like a religion trying to discuss alternatives.

Don't take me wrong, this is a great starting point...

But what I'd really like to see is a comparrison of top sites in the same niche industry comparing head to head, in terms of sales, how long the servers stay up, how many times they had to reboot, anything else we can use as a fact, to prove that coldfusion is the more profitable and more stable solution.

I believe that this is part of the a new trend of trying to prove things by example, rather than just explaining why coldfusion beats java, asp,, php etc....

I'd love to hear examples of top sites that compete, like a cf vs php or cf vs etc...Bring up your favorite/top cf sites...

Let's show coldfusion competes in the real world.

Query Bottlenecks

One of the biggest barriers to scalability and long-term performance is how we logically grab the flow of data from the database.

So I am creating a list of things to not do, and to do.

1. Do not loop thru cfquery, because each cfquery creates a seperate jdbc/odbc connection which takes additinal memory/processing power etc. So look at the different queries and see if you can combine them.

But it depends on the relationships, if for example you have two queries and the second is looped over by the first one, perhaps you can do a join.

Remember the power of group by in the cfoutput statements....

You can use this technique, based on the join you use, to combine the queries and still get the same results.

Remember the issue is to reduce the number of cfqueries, as much as possible.

2. Do not ever, ever do select *. It's always best as a standard and for performance, to specify in the correct order, the exact field you need for your query.

For example if you have a table of 40 fields, and you run a query that needs only five, think of how much wasted memory/cpu, you are using improper coding.

If coldfusion is going to be the best language, then we have to always code for longterm, scalable performance, even if it takes us longer to type in.

So once you have performance nailed down, then it is a matter of improving upon it.

1. Such as moving complicated, highly used joined queries into views or stored procedures.
2. Review the performance of the page, by debugging, look at the cfincludes and cfqueries for those that take too long.
3. Learn all about caching, when and where.

Cachedwithin, Cachedafter, or cfqueryparam

CFQUERYPARAM is a very powerful tool, both to help validate incoming url/form data to a specific data type. Which is great for preventing cross-scripting, and errors.

For oracle databases, it actually improves performance, because of something called bind-variables. Basically if you have 1 query running dozens of times, but just a different value in the where clause, then bind-variables, allow the database to treat the queries as the same query, which caches it and improves performance.

In the end, query bottlenecks, are caused by poor planning, and poor coding. These can be overcome, and they should be overcome.

Coldfusion has so much potential to be the most scalible web development language/server, if we code that way.


Monday, August 02, 2004

Cracking into ColdFusion - SitePoint ColdFusion Blog

Cracking into ColdFusion - SitePoint ColdFusion Blog

I find this extremely fastinating, because who knows what special needs we have, that we need to roll our own versions of cfml tags?

Like for me, example, I'd love to roll a version of cfdump that is printable, besides all that beautiful dhtml.

I find it can take coding to a different path, to add things we'd all wish for.

I mean once you have a stable platform, that is scalible and delivers on it's goods. Then it's a matter of customizing it towards your specific needs.