Jun 24 2008

Different way of thinking PHP vs. Ruby

It’s interesting to note the differences between these two. I have found a few weeks before Peter Marklund’s excellent rails 101 pdf (a whopping 340+ pages of slides).

I am still going through it, but as I have a few years php experience (and still finding exciting new functions like compact and extract), I sometimes think about whether some of ruby’s features work the same way as php. The answer is usually: no.

For instance, in ruby you can do:

var1 = vara && varb && varc

a var is false if it’s ‘nil’ or ‘false’ everything else evaluates to true. It’s not the same with php, where 0 or ‘0′ also evaluates to false (and maybe some more).

In the above if all values eval’ to true then the last (varc) one’s value is put into var1. There’s also:

var1 = vara || varb || varc

Which works similarly, but the first variable that evaluates to true is assigned to var1.

 

My favorite one though, is how you can exchange the contents of two variables in ruby:

a, b = b, a

That’s all! (intuitive, you can’t deny)

It - of course - does not work with PHP. However since I was curious if a syntatically similar solution can be achieved with it - after some fiddling I come up with it for PHP:

list($a, $b) = array($b, $a);

Looks similarly (and as I do not know what happens behind the scenes in ruby they might just work the same way - but PHP exposes more of its inner workings)

Well, whatever. The more I know about ruby the more I like it. :) 


Jan 8 2008

Magpie developers

Magpie means szarka for my hungarian readers. You know the one that likes to collect shiny new things.

This is exactly the case with new frameworks, languages popping up every day. It’s a thing that software developers have to live with constant change (for the better usually) but that’s just how this profession works - and you should like it. However if you can’t focus long enough on one thing - the same will happen with the next one and you’ll never gain enough proficiency in anything. This post describes it in more detail. I like what the guy’s doing - despite being a M$ guy he knows what he’s talking about - and no flaming can be found on his site.

So today I officially announce my focus on exactly these 3 things in the (open source) web-developer world:

  • Ruby on rails
  • Drupal 5.x and up
  • Code Igniter 1.5 / Kohana 2.x (its latest reincarnation) framework (PHP)

I know a lot others, and used them more or less, but I like these the most. There are countless other and equally good baseline frameworks (zend framework, symfony, cakephp, etc.) but you need to draw a line somewhere. I might get a few things from Zend though - it’s modular architecture allows you to use only parts of it. And we have not even talked about javascript frameworks (jquery, extjs, yui, prototype rule it at the moment) - you need to grok to be able to get along.

I like ruby/rails because it gives a fresh way of looking at things - and now it has gained enough wind that even the java / .net guys are started to copy the architectural ideas from rails.

Drupal has a vast array of extensions in the form of modules - yet the core is simple enough for anyone who wants to understand how it works. Once you figure out how the different pieces fit together it’s basically like playing LEGO. Sometimes writing some glue code and trying to figure out why some piece does not work the way you thought it should. :) I have just heard about a 12 year old (russian, of course…) little guy, called dmitry who will go to the next drupalcon in the states together with our longtime drupal hacker friend, chx (Karcsi bacsi de Negyesi) - the interesting thing in it is that the drupal community has thrown together something like 600 USD in 1.5 days for the guy. :) How cool is that?

And in the end: Code Igniter / Kohana because of its excellent documentation (way better than anything else I have seen so far. Simple, easy to find things, almost complete and the API is one of the more intuitive ones). Now the founder’s focus is on his commercial endeavours and stopped developing it, but as it was simple, fast and yet powerful - a community started forming around it - and they basically continue evolving this framework under the name Kohana. They switched to support only PHP5 + - which is also a welcome move (finally).

That’s it. I also would like to experiment with the Cocoa API on Mac OS X (there’s even a Phocoa framework in PHP that copies it to the web world), and have played with Java - but you know computers are not the only thing in this world. I’ll leave the rest for others to play with and explore, learn and evolve.


Oct 28 2007

Getting rmagick on Leopard (OS X 10.5)

As you might be well aware, the latest OS X version includes ruby (1.8.6) and rails (1.2.3) installed plus a few other gems into /Library/something. Which means: system-wide, and apple might upgrade them in later minor upgrades to leopard. There’s already upgrades to the 1.2 rails line and rails 2.0 will be out soon (if not already out).

So, basically rmagick is not included amongst the gems. If you wanna do anything about image manipulation in your rails app, then you just can’t live without it. Period.

I decided to install macports this time, with my new Leopard installation. I had concerns against its default /opt install location (I would just have preferred /usr/local) but now that I did some reading on their website I know why they needed to choose that path. Here are the steps:

  1. Install the XCode developer tools (with the X11 sdk, bit it’s default I guess) from your snazzy little Leopard DVD you just bought.
  2. Download the latest macports package for OS X 10.5 (link)
  3. Install it (will take a short while, as it updates its package list upon install)
  4. If you have not created a ~/.bash_login or ~/.bash_profile or ~/.profile file in your home or you have no idea what these are then skip to 6 (and learn about them by the way)
  5. After macports has done if you have an old .profile or .bash_profile or .bash_login file first of all keep only one of them and organize your shit so that all what’s needed is in one file that you keep. Now open ~/.profile that the macports install has created and copy the lines from it to your chosen file.
  6. open up Terminal.app from /Applications/Utilities and type port. It should greet you with a few lines. Now type quit to exit from it. If it says something ending with command not found - you fucked up something. Try to close all Terminal instances and reopen and retry. If still no success try to google for a solution or read more carefully what I write.
  7. The following is courtesy of this guy. All the below are typed into a terminal window. The command(s) will ask for your password. Do not panic.
  8. sudo port -v install tiff -macosx
  9. sudo port -v install ImageMagick
  10. sudo gem install rmagick
  11. All should compile under 15 minutes on a decent macbook pro. You will see lots of lines from gcc and make scrolling by - just enjoy. At the end you can test for a successful install by typing “gem list rmagick”. At the time of compilation I got rmagick (1.15.10) installed.

For the more technically inclined: when you install rmagick bu sudo gem install … it puts it under /Library/Ruby/Gems/1.8/gems/rmagick… That’s why you need to ’sudo’-it. It is a bit of a disappointment though as I thought I might be able to install my own gems into my user home. Well the positive side of things this way is that all users of the system can access these gems. :) Even if you are the only user…