Finding a Shortcut

Being a self-taught developer, I haven't often been able to compare myself to other developers. At least not in direct ways like, how do you know what solution to use for a problem, or why your coding style is the way it is. The best I've been able to do is go by the code examples I learn from.

One thing I've continually done as a developer, though, is try and find shortcuts. "What's the quickest way to accomplish something?" I've heard this is a trait often found in good programmers. (Maybe that's just wishful thinking!)

Here's the kicker: it's not about reducing the number of hours I work in a day because that never changes. It's about finding the easiest way to solve a problem for next time, even if it takes me a relatively ridiculous amount of time to solve the problem this time.

What has consistently happened as a result, though, is that my code is smaller and more managable and often faster because of the reduced complexity. That benefits me both this time and next.

Published August 04, 2006 · Updated September 14, 2006
Categorized as Opinion
Short URL: https://snook.ca/s/634

Conversation

17 Comments · RSS feed
acts_as_flinn said on August 04, 2006

I tend to agree with this. Sometimes it is hard to know when a solution is really going to be useful in the future and I should spend time on it now to save for the future or if this one particular case is a waste, and I should just GTD the hard way. Also as a self-taught coder, I find myself trying to write "reusable code", when most of the time I can just copy and paste useful code.

Elliot Swan said on August 05, 2006

Keeping solutions clean always helps, as you'll always end up using it again sometime.

Andy Kant said on August 05, 2006

For solving problems, buy the book Design Patterns. It is a great book that has the best practice design for software for many common problems. Every serious programmer/engineer should keep a copy close.

I would recommend getting some formal education. Not that it isn't possible to get by without it, but the difference in the quality of the code is pretty noticeable most of the time. I have taught myself every language I know except for C++ (and its a pretty long list), but the knowledge I acquired through education has been invaluable.

Knowing what solution to use comes with experience, but that Design Patterns book will definitely help you get there. I would also recommend buying a book on algorithms, but I don't have any specific ones to recommend.

For coding style...thats mostly preference, the most important thing is to stay consistent.

Also, what seems like the quickest way isn't always the quickest way nor the best.

xonecas said on August 05, 2006

I really agree with you and I have the same guide line in my work. I've learned all that I know about beeing a webdesigner and a backend scripter from Internet resources, and I always believe that there is an easier way to acomplish my goals and I'm always looking for it.

blinking8s said on August 05, 2006

Two thumbs up (I agree)...I had a very similar discussion with a co-worker a few weeks ago. It applies far beyond just being a developer (something I am far from), yet into every practice of a technical field. I am a photographer, web geek by hobby (although I did get a formal education in web design/digital media just never pursued it as a career) yet both fields were the same learning concepts. Even in school my key sources of learning were examples, taking the example and trying to find ways to cut it down, be better, be different, then once I had totally broke everything, the next time around I knew better. In photojournalism I learn from example, looking at others work, and I only improve by going out and finding what works, what doesnt work, what I will do different when I pick up my camera in a similar situation in the future.

Fredrik Wärnsberg said on August 06, 2006

I have a friend whose hobby is to re-write his existing code to minimize it and to make it as compact as possible. I've never seen more complex if-statements in my entire life. :P

I don't totally agree with you thought, I'd rather have an elegant solution rather than the one that is the fastest one to write.

Jonathan Snook said on August 06, 2006

Fredrik: wouldn't they be one and the same? What would be fast to write but not elegant?

Don Selkirk said on August 06, 2006

I am also a self taught. I actually got alot of my base computer knowledge from john, Hey by the way. I've worked for a couple web companies now and one constant instills. Fast is good, Fast and Elegant is better. Is it practical, never usually. Projects never get the best options, just the best solutions. On how fast or elegant it is it comes down to the coder and their best practices. We all learn from what were doing. The greatest thing about the web is the constant state of growth. In another year who knows what will be available, ajax now, web 3.0 next? The great thing is we learn. As long as we do that (and still read or old code, hehe) there will always be room for improvements.

Mikey McCorry said on August 06, 2006

"What would be fast to write but not elegant?"

It depends on your definition of elegance. I once had a collegue (a programmer of 25 years) who prided himself on his ability to quickly condense long-winded perl functions into 1 or 2 lines of re-usable code. To him, this method was elegant, but for me, it was anything but, especially when I needed to modify it, even slightly. Thank goodness that perl code is not so relevant these days.

Jason Kataropoulos said on August 07, 2006

Elegant is pretty subjective according to a developers culture and habits.

One builds his library of elegant and reusable code for HIM! As long as this is reusable and elegant for him he has done a great job!

The problem begins to appear when other people need to use his library (usually happens in companies) and that’s when developers have to comply with the companies’ coding styles. That’s why in big companies there is always a training period for new developers, they learn to code accordingly.

To me, good and elegant code is whatever makes me happy coding and whatever makes my coding easier and faster.

Jonathan Snook said on August 07, 2006

Personally, simply moving logic into a reusable component is not my idea of elegant. It's practical, for sure.

Elegant for me is where you discover a different approach to something that just makes your life easier. Like, discovering how to do a regex that simplifies your string matching to one line instead of looping through a string. Or doing some SQL function that saves you from having to do a lot of work at the PHP level. And in finding this new approach, the code is shorter, easier to read and (often) faster.

Andy Kant said on August 07, 2006

I remember the day that I finally understood all the random characters that made up regular expressions; that was a fantastic day. :D

ActiveRecord is another big jump for making SQL easier and more elegant but you're already using CakePHP. Recursive algorithms maybe? You probably understand that by now anyways.

There isn't a whole lot of jumps out there until someone takes a step and creates them.

Jason Kataropoulos said on August 08, 2006

Andy, I am still waiting for that day to come :)

Jonathan, database servers are becoming powerfull enough to handle business logic. Do you think that this is messing up the 3 tiers by pushing business logic to the data tier?

Jonathan Snook said on August 08, 2006

Jason: database servers like MS SQL Server and Oracle have been powerful enough to handle business logic for some time now.

I think the problem (at least for me) has been, what is "business logic"? Like data validation... is that something that the database server should handle? It does in part by defining data types and lengths and foreign key relationships. But should it go as far to say that a user can only have 5 items if they are an administrator?

Most of the MVC frameworks out there like RoR and CakePHP take the philosophy that the model (and data validation) is handled at the framework level. The database just becomes a storage mechanism. Even, then, you still have to decide what should go in the model and what should go in the controller.

I don't have any answers to this one. :)

Jason Kataropoulos said on August 08, 2006

Exactly,

I had such conversation with one of my colleagues a few days ago and we decided that there is no generic way to clearly define tiers. But you can define the tiers when looking at a specific application. In other words when you define application boundaries, then you can define the tiers more precisely.
Of course, this is a topic on which we could contemplate for ever and is different from the article above!

Just wanted to hear your opinion…

Thank you!

Andy Kant said on August 08, 2006

My rule of thumb for where to place business logic for data:

Is performance important?
-> Yes, then embed the business logic into the database if possible since databases are optimized for these sorts of operations.
-> No, put it in the framework.

Another consideration is whether the dataset is going to be used for other purposes such as reports. Handling this in the framework results in tight coupling and will require you to reimplement your dataset in each different technology you use it for.

Scott said on August 10, 2006

It's about finding the easiest way to solve a problem for next time, even if it takes me a relatively ridiculous amount of time to solve the problem this time.

Now that is a sign of a good programmer!

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.

Want to learn about scaling CSS for large projects?

I'm available for full and half-day workshops on scalable CSS architecture. I can provide on-site training for your team. Interested?
Get in touch.