Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

I've been to a ton of conferences and heard a lot of keynote speeches, and I don't remember many of them. Nick Petreley's Clarion keynote of many years is one I recall, but mainly because of the cool Pinky and the Brain clip he showed and not because of what he actually said. And Hank Asher's Clarion keynote has stuck with me because a few years later I was contacted by a lawyer interested in my recording of that event. 

But at the Open Source Convention (OSCON) in 2006 I heard Six Apart's Anil Dash present Trying to Suck Less: Making Web 2.0 Mean Something. I was floored. It wasn't so much his take on web development, as good as it was. It was the frank admission that what we do as software developers so often sucks. And that's okay, as long as we try to suck less.

I came away with a whole new perspective on my work as a software developer. I've written code that I'm proud of, and code that should never have seen the light of day.

Some of my best code from years ago really really really sucks. But it was the best code I knew how to write then. 

The real question is, how do I improve my code right now, using the best practices that are available? 

The reality is there's a whole lot room for improvement in the Clarion world. Yes, we have a great tool that <insert your favorite rant about Clarion's magnificence here>.

That doesn't mean flies to a frog. Your customers either don't or shouldn't care about what tool you use. They care that you can deliver reliable code that does what they need it to do, at a price they can afford. Similarly you care (or should care) that you can create the required functionality with the highest reliability and the lowest total cost. 

Clarion's code generation technology provides a huge assist; you get rapid production of highly reliable code, easily maintained and extended within the AppGen environment. 

But what happens when you want your app to do something the AppGen and its many templates can't handle? 

 That's when you start writing your own code. And that's when you really start taking responsibility for the quality of your own applications. 

A lot (though not all) of what we can do to suck less involves writing better code. 

Sucking less

Here are some of my favorite ways to make Clarion development suck less:

THE BIG ONE: Get that business logic out of embed points!

Embed points are like crack, and way too many Clarion developers are embed-heads. It's just so easy once that embed point is open to keep on writing. Stop! NOW!! Code in embeds is typically non-reusable, awkward to test, difficult to maintain, and frequently unreadable due to excessive length. You need to put that code somewhere you can test it and reuse it. To some degree you can accomplish this by moving the code to source procedures, but classes are generally a better solution. Which leads to...

Learn object-oriented programming

I know, you don't have to know OOP to code in Clarion (even if ABC apps rely heavily on classes). But there's a reason object oriented programming is ubiquitous. It. Just. Works. And it can make so many things about development much better.  

Create unit tests for your business logic

Use ClarionTest or CWUnit to unit test your business logic, or set up your own testing framework/coding convention. Be able to test your business logic apart from the user interface or the database. This will make development, maintenance and even design easier. Once your business logic is right you can write it into the UI and/or the database.

Take a layered approach

Start thinking about your apps as having distinct areas of code responsibility: user interface, business logic, database access, and the database storage (there are other ways to break this down, but this is a common approach). Although Clarion procedures tend to combine all the layers in a single procedure, you can still adopt this kind of separation when dealing with your own code. 

Use version control

Keep your Clarion environment and your applications under version control. 

Move to SQL (if you haven't already)

There are lots of SQL flavors out there, and almost certainly you can find one that is a good replacement for your current flat file database. Once you go SQL you never want to go back. 

Make your code readable

Use fully descriptive names for variables, procedures, classes, methods etc. Keep individual code blocks (procedures, methods, routines) short and focused on one task. If you find yourself needing to comment your code then it's probably too obtuse; code should be its own description. Adopt a naming convention (but please, not some variation on systems Hungarian...).

Create integration tests

Unit tests run standalone and are typically lightning-fast and run constantly during the development phase; integration tests use databases and other external resources. Because of these external dependencies they typically run more slowly and are more fragile, but they can also be a vital part of your development toolkit. 

Create a build server

Once you have your code under version control you're not that far away from creating a build server that sees when you've committed code to the repository, pulls that code and does an automated build. Especially useful in large multi-app systems with multiple developers. 

Automate your tests

Ideally your tests should run as part of your automated build process, but the tooling for this isn't readily available yet. 

Adopt Test-Driven Development

Whether or not you use one of the existing Clarion unit testing frameworks, you can still adopt the TDD approach. TDD has numerous benefits not just for code reuse and reliability, but also for code design. 

Take an API approach

The golden age of the standalone desktop app running on just one platform is coming to an end. That doesn't mean the end for Clarion, but it does mean that Clarion's role is beginning to change. A system might have a desktop component, a web component, a mobile component and any number of services. Think about how you can extract functionality from your code base. Perhaps you have code that a mobile app might need to call, using JSON as the data format. Or there's a web app somewhere that needs to call your code via a web service. 

Break long processes down into Hanson Loops

What's a Hanson Loop? It's a construct Mike Hanson once provided for me in a procedure I wrote, and which I liked so much I've used it many times since. Read more... 

Use bug tracking software

I've used FogBugz in the past; I'm currently a huge fan of Jira. You have a world of choices; find a bug tracking system that fits your needs and use it. This is especially important in a team development environment. 

 

 

  • No labels