Tuesday

Drush, Delphi History, Array Push, Double Linked Lists

 
 Programming
 
From Scott Orgera, your About Programming Editor
 
 
Creating a struct from a hash in Ruby can be difficult, but the reward is worth the effort. In this week's newsletter, we walk you through the process. We also explore coding double linked lists in VB, using more than one CSS class on a single element, generating random numbers in Ruby, managing Drupal from the command line, and much more...
 
Follow us on:
 
 
Sign up for more free newsletters:
 
How Do I Create a Struct from a Hash?
You have a hash of values and you want to create a struct object from them.  How would you do that? Structs and hashes are structurally very similar.  There's not a very simple route to get from A to B, however, but with a bit of magic you can get the job done.

A Struct is a bit of an odd thing in Ruby. Ruby is all about dynamic programming. You don't have to define rigid structs as in C or C++, you just make a hash and store values indexed by keys. The fact that some hashes only have certain keys is merely a convention. If it has more keys (such as if you implemented a new feature), it doesn't break anything. Adding new elements to a structure in C or C++ could be disastrous if any code relies on the exact offset of some elements. So why would you want to go back to rigid structs? One word: speed. Structs can be much faster, and perhaps more importantly they have predictable performance characteristics. One struct object isn't going to be slower than another because unlike hashes they have a defined, static set of elements.  READ NOW

How to Quickly Run an HTTP Server with Ruby
Quick, run an HTTP server to serve files out of the current directory. Not so easy, is it?  Even with WEBrick it can be difficult and not easy to remember. And if you can't remember such an off the cuff procedure, why even bother?

Enter the un library. That's right, it's called un and it's part of the Ruby standard library. Why is it called un? Because to require a library from the command line when running Ruby you use the -r switch, so it becomes ruby -run. Now the name makes sense, but what does it do?  READ NOW

VB: Coding the Double Linked List the Hard Way
The linked list is one of the foundation concepts of programming and it's supported directly by VB.NET language elements. Sure, there are higher level ways to uses lists in VB.NET. But you can code a list the hard way too, which is actually a great learning tool. This article shows one way to do that for a double linked list. But unlike other articles you might see, this one approaches the solution with a great deal of explanation because understanding this example is an excellent start to making sure that you comprehend what's really happening in your code.  READ NOW

Using Multiple CSS Classes on a Single Element
Cascading Style Sheets (CSS) allow you to define elements with classes to provide additional information about that element, give it different styles and connect with it via JavaScript -- and you don't have to limit your elements to just one class. You can set multiple classes on an element by separating them with a space in your attribute. READ NOW

 
ADVERTISEMENT
Featured Articles
More from About.com
Sign up for Shareables!
An every-morning rundown of the day in history, with headlines and trends produced by your pals at About.com. Click here to sign up! It's free (of course) and we think you'll like it!
Want More From About.com?
Check out our social channels tailored to every interest!
Sign up for more free newsletters on your favorite topics

You are receiving this newsletter because you subscribed to the About.com Programming newsletter. If you wish to unsubscribe, please click here.

If you would like to unsubscribe from all newsletters sent from About.com, please send an email to optout@about.com with "Unsubscribe" as the subject line.

Contact Information:
1500 Broadway, 6th Floor
New York, NY, 10036

Privacy Policy © 2014 About.com