Author Archive for liquid

Quick tip: Variable Naming Conventions

I am just in the middle of a huge code re-factoring. I am dealing with a huge amount of code which was previously made by someone else. Most of you probably know that working with someone else’s code is most of the time a pain in the ass. It gets even worse when it leaks in documentation.

So, for this really simple reason I decided to start writing quick-tips about coding which will hopefully help keeping your code clean and easy to understand. Here’s the first one.

Use reasonable and self-explanatory variable names

Think about how much time you often spend on figuring out what a variable is used for or what it is supposed to be. There are some bad examples:

# a lot of code before...
 
$b = SomeObject::getByID(12);
$na = "Cutting Edge";
$nu = 12;
$c = array('Audi', 'BMW', 'Mercedes', 'Aston Martin');
 
# a lot of code after...

Could you explain what those variables are meant to be? You will probably need to find the answer for that some other part of your code. A better way is to indicate the types and use self-explanatory variable names:

# a lot of code before...
 
$oBox = SomeObject::getByID(12);
$sName = "Cutting Edge";
$iNumber = 12;
$aCars = array('Audi', 'BMW', 'Mercedes', 'Aston Martin');
 
# a lot of code after...

In this example, the first characters indicate the data types of each variable (”o” means that the variable in subject is an object, “s” stands for strings, “i” indicates integers and so on. Pretty straight-forward.)

You may ask why this is a big deal. I tell you:

  • Easier to understand,
  • You know what to expect from a variable,
  • Others will understand the structure of your code a lot faster,
  • Also, it will be even easier for you too to maintain if you need to get back to your own code after a while.

So guys, please remember: Keep your code clean and sensible.

ECLM theme ported to XCode

A couple of months ago I’ve published our TextMate theme file which turned out to be really popular. Since that I’ve started experimenting with XCode but I could not get used to any of its default color themes.

XCode using the ECLM Color theme

XCode using the ECLM Color theme

I started to port our original TextMate theme to XCode. This is a quick screenshot of it, download will be available soon.

Twitter Said To Be Abandoning Ruby on Rails

There was always a mess and confusion around the scaling abilities of Rails.

We’re hearing this from multiple sources: After nearly two years of high profile scaling problems, Twitter is planning to abandon Ruby on Rails as their web framework and start from scratch with PHP or Java (another solution is to stick with the Ruby language and move away from the Rails framework).

.. as it was written yesterday on Techcrunch.

On the other hand, David Heinemeier Hansson (creator of Ruby On Rails) wrote a post on Loud Thinking (his personal Blog) about the scaling opportunities of the framework.

Well, I am about to dig deeper into this very exciting question and share my experiences.

UPDATE: Just got noticed by Arnold Funken on Twitter:

Element.Update(), flash and IE7

Yesterday I ran into an issue with IE7 again (well, I assume not too many of you are surprised, ehh).

When I was trying to move an element in the DOM (actually update) with an other element’s innerHTML including a flash object, the movie (.swf) forgot to load. Right clicking on the flash file you can see the following message, greyed out:

“Movie not loaded”

This is an example snippet of the code:

<div id="video">
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="184" height="140" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="bgcolor" value="999999" /><param name="quality" value="high" /><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="src" value="/videos/15.swf" /><embed type="application/x-shockwave-flash" width="184" height="140" src="/videos/15.swf" allownetworking="all" allowscriptaccess="always" quality="high" bgcolor="999999"></embed></object></div>
<script type="text/javascript">
$("otherElement").update($("video").innerHTML);
</script>

Using IE7, Prototype 1.5 and Flash Player 9 on Windows XP.

This problem does not seem to occur in normal browsers (like Safari or Firefox), they load the movie file perfectly. I thought it would be good to share with others, maybe you guys know a workaround, or I can warn others before they will have to face the same problem.

Safari 3.1 and Prototype conflicts

Apple has shipped the new version of Safari last week, which has enhanced usage of JavaScript. From now on Safari 3.1 natively supports getElementsByClassName, which is good, Safari can process and execute this function even faster than before. The upcoming version of Firefox also implements native support. Good. Performance upgrades are always good, and even more welcome nowadays in our ‘ultra-interactive’ web of 2.0 applications.

But on the other side, this causes issues for Prototype-based websites, there is a conflict between the native and the Prototype methods, which both have the same name.

For example if you are accessing a bunch of elements like this:

$('foo').getElementsByClassName("bar").each(Element.hide);

It will not behave like it did before. Hmm. You do not need to scream and shout now, until the Prototype team comes out with a solution you can still use this syntax:

$$("#foo .bar").each(Element.hide);

Easy, huh? So be aware that your sites may be broken for Safari users and replace the affected lines with the workaround mentioned above.

Rails 2.0 is finally out

Yes, you are right. It is finally finished after about a year in the making. This is a fantastic release that’s absolutely stuffed with great new features, loads of fixes, and an incredible amount of polish. So let’s digg into the new features and everybody: update your stuff to get even more funky!

Update details can be found here.

eclips3.media (ECLM) TextMate Theme

I usually check several development forums and I’ve found a thread on Rails Forum about development environments where people share a screenshot about their tools. I did this too, after several examples. Since my TextMate Theme got so many respects I decided to share it with the public.

One of its main benefits is that it separates the different data structures, functions, variables, comments, etc. So it is easier to look up your code.

Development Environment

So, if you like it, it can be found here.

Copyright: This theme was originally improved from the one what we can see in Ryan Bates’ Railscasts.

Problems with RMagick 1.5.x

Last week one of our webistes went down for some unknown reason, and I’ve found this kind of error message in production.log:

LoadError (Expected xy file to define ...)

Of course this is a useless error message which means Rails couldn’t find a controller file which has been still at its proper path of course. What to do now? If you need a more detailed error log, there is a solution to force Rails to log errors in deeper detail, just set your caching classes to true in your environment.rb file:

config.cache_classes = true

After restarting the webserver, and reloading the page, I could get a proper and useful error message, Rails pointed that the error is in RMagick gems. Take a quick look on the new error message in the log:

RuntimeError (This version of RMagick was created to run with ImageMagick 6.3.3
but ImageMagick 6.3.6 is installed on this system. You should either
1) Configure and build RMagick for ImageMagick 6.3.6, or
2) download ImageMagick 6.3.3 from file:///usr/local/share/doc/ImageMagick-6.3.3/index.html and install it.
):

Now this is something what you can use to start debugging. After reinstalling RMagick, the problem has been solved, and the site was up and online again. Just do the following 3 easy steps:

gem uninstall rmagick
gem install rmagick
apachectl restart

Done, hoorraaay!

Rails goes v2.0, shortly

Behold, behold, Rails 2.0 is almost here. Take a quick look here to check out the new killer features. There is a preview version available as well. Must be seen!

Update:

This morning (November 29th) the Rails team has released RC2 so if you are a freak who is keen on the latest builds and wants to check out RC2 - use the svn checkout command of:

svn co http://dev.rubyonrails.org/svn/rails/tags/rel_2-0-0_RC2 vendor/rails

The people who make websites

In April 2007, A List Apart and An Event Apart conducted a survey of people who make websites. Close to 33,000 web professionals answered the survey’s 37 questions, providing the first data ever collected on the business of web design and development as practiced in the U.S. and worldwide. Now  the results just became public.

The findings they present here have never been seen before, because until now, no one has ever conducted public research to learn the facts of our profession.

Take a quick look at the website, read the article and check out the results which are available in different formats, such as Adobe PDF. (1.6 megabytes)