Ruby -vs- PHP Showcase: nsupdate script

This a showcase of a Ruby script competing with a PHP script. The main focus is on useability and ease of implementation. The scope is a single simple script (say 10 to 100 lines).

(originally from Mar. 2007)

Please note that I don’t intend to benchmark the competitors. As I said the scope is limited and the focus on getting it done now. Then both could be run in client mode (off-web), CGI or fully embedded, I’m confident you can optimize if the need comes up. Also note this is an example to promote the use of Ruby not bash PHP.

The roots of PHP lie with PERL. And Ruby’s syntax is inspired by PERL. This way we should see some common elements in both PHP & Ruby and be able to do things with a similar approach.

nsupdate script in Ruby and PHP

The PHP nsupdate script copyright is with Chip Rosenthal, the minor formatting changes here are not intended for redistribution. The Ruby example was written alongside the PHP source and formatted to match the line numbers.

Some noteworthy differences:

  • The output templates are simple strings in PHP and inline here-documents in Ruby. There is no noticeable difference between those or the escapes to include variables. The ‘eval’ statements at the end of the script are much simpler in Ruby though.

  • The Ruby script uses the postfix notation for conditionals which simplifies get_hostinfo() a bit. Also the hash merge eases applying default values here.

  • Ruby always returns a value, this is used in validate_host()

  • the Ruby script uses YAML to format the config file. YAML is very clean and effective here and comes readily integrated with Ruby. I recognize PHP scripts could use some bolt-on INI-style file reader to get par.

And here you go, the source code files for the Ruby -vs- PHP Showcase: nsupdate script. (I don’t use these scripts anymore. They should be fully useable still, YMMV.)

Source codes & Config files are attached below

I hope you get a feeling of Ruby’s way, see that the differences are not that vast, and perhaps you get eager to try this yourself!

MP3 Scan + Repair

The audio repair tool to check and fix all your MP3 files.

Check and repair your MP3 audio files.

Some of your audio players might be picky or play choppy sound. Scan and fix all your MP3 files for best performance! And it's free, too!

MP3 Scan + Repair

Mouse Acceleration for OS X

Set up extended speed parameters for your mouse.

Extended mouse settings

The Mouse Acceleration PrefPane is a GUI and startup item to Richard Bentley's MouseFix.

You can set up extended speed parameters and acceleration curves for your mouse.

  • Increase mouse pointer precision
  • Speed up your mouse movement
  • Set mouse acceleration parameters
  • Full control with just two simple knobs

Mouse Acceleration for OS X

About the Author

Hi there! I'm Christian Zuckschwerdt a freelance software designer from Germany. On this blog I'd like to share some free and open source software for GNU/Linux and Apple Mac OS X.
There are also some themes and tricks for the Drupal CMS. And then the occasional hardware or gadget hack. It's all free and mostly licensed under the GPL or CC.
Write a comment or send me a mail. I love to hear from you!

About FOSS

Do you know how much free and open source software is involved in creating and delivering some basic web pages?

This triq.net blog is rendered by hexo themed with nunjucks compiled by nodejs served by apache httpd secured with openssl stored on MariaDB running on gentoo linux, edited with vim deployed by openssh, graphics done with inkscape and gimp.

triq

zany@triq.net
triq.net blog
© 1999 – 2017 Christian Zuckschwerdt.

Links