Too Cool for Internet Explorer

Saturday, May 8, 2010

Diving into HTML5



I have chosen XHTML since I will apply some effort on Web development stuff.

Last Year W3C have decided to stop the XHTML development.

So, it is time to give XHTML a break, and start learning HTML 5 and CSS 3.

Of course we have many other HTML5 references on web; here is my first attempt into HTML5.

First things first: the Doc Type declaration.

Compared with my previous one:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

It couldn’t be more appropriate, simple and easy:
<!DOCTYPE html>

What we have been doing using the div tag, could now be done more semantically with, article, section, header, footer, nav and aside tags.

A few phrasing elements can help when including complementary information like: time meter and progress tags.

And a lot of new resources to be explored in the near future, like: video, audio, data attributes, microdata, native drag and drop, canvas, DOM storage, Client side SQL, new form controls, and some more.

At this point I need to do something practical, so, why not turning my own personal page into HTML5. Good chance to change its outdated design and a few concepts.

Hands on!

Here are the steps I have followed:

First, take the former page and a few ideas on what to change.



And here is the altered page:



It was an intermediary version, a cleaner one, but still using XHTML.

The tool I have used most in this phase was the ColorZilla Firefox Plug-in.

Since I was trying to keep the color scheme close to the one I have used in the previous version, this plug-in really helps.

Now, the big change!

I was looking for a different approach. My web page would show a more intimist profile, giving me a chance to explore HTML5 basics.

And here it is:



I have made a self-explaining layout from this new version of my page, where each new tag could be easily found.

I have also provided a full HTML5 page wireframe, so anyone could start working on it right now.

What to do next? I think a little work using the canvas tag will be.

Saturday, April 10, 2010

Who cares about a nanosecond?

Things are going faster and faster, so, why still measuring times in a second precision?

Could you think about how many files are uploaded from users in a specific city within a second?

Let’s say, any country capital with a high speed broadband service.

Try to put them all in order. Which arrives first?

Most of the current relational databases support Timestamp data:

Oracle ........ '2007-08-08 09:00:00.123456789'
DB2 ........... '2002-10-20-12.00.00.123456'
PostgreSQL .... '2003-07-29 13:19:30.532'
MySQL ......... '1970-01-01 00:00:00'

But most of it doesn’t consider nanoseconds properly.

People tend to consider that only Real Time Systems have better precision of time measurement needs, but that is not true.

I have recently developed a business application where users can upload files.

Files are uploaded in groups (fifteen maximum). It was important to know the order on which files have been upload.

Depending on the size of the files and users’ internet broadband capacity, some files could be uploaded in the same second.

So, that is the reason to store the uploaded date in the table as a Timestamp column.

The problem starts when trying to feed the required data using the language resources only. I know we can provide current timestamp from the database itself, but if you are not using a relational database and needs to store the timestamp?

Java and Python for instance, have nanoseconds support, but deal with them separately from the date and time. And about Ruby?

The Good new is that Ruby 1.9 does the job nice this way:

Time.now.strftime('%Y-%m-%d-%H:%M:%S.%6N')

Where you can specify the desired precision in %3N, %6N or %9N, but will need a superfast machine to test them all.

Here is a working sample:



Another consideration you must take into account: the O.S. used:

  • Solaris and Linux already support nanosecond precision.
  • The situation on Mac OSX is not that good, since only microseconds are available.
  • Windows, on the other hand, supports nanoseconds, but have a 10ms granularity limit.

So, depending on O.S. running your code, you may need some extras to get the timestamp in the complete form.

The Bad new is that Ruby 1.8 doesn’t support nanoseconds.

Back to the real World, we must admit that most of people out there are using Ruby 1.8.6 under Windows.

So, I have made a working snippet for Ruby 1.8.6 on Windows that could at least, provide data to the PostgreSQL centisecond format.

Saturday, March 13, 2010

Ruby TransParenTheses

First thing first, the definition:

Parentheses (singular, Parenthesis)—sometimes called Round Brackets, Curved Brackets, Oval Brackets, or just Brackets, or, colloquially, Parens.

Contain material that could be omitted without destroying or altering the meaning of a sentence.

I think the above definition, must be considered when discussing about the non mandatory Parentheses use in Ruby.

On many discussion groups, people are questioning Matz’s option to not make the use of parentheses mandatory in Ruby Language, mostly around Ruby methods parameters.

Apparently this decision is becoming stronger.

If you run the following piece of code in Ruby 1.8.6, you will get a warning:

p Array.new 3, 1

ptest01.rb:1: warning: parenthesize argument(s) for future version

The same occurs with this one:

p Array.new (3+1), 1

ptest02.rb:1: warning: don't put space before argument parentheses

But if you run them in Ruby 1.9.1 they will pass with no warnings.

Do you really think it would be better this way?

p(Array.new((3+1), 1))

When developing an application I like to put myself in the user’s shoes.

As a user of a reading text (program), I would like to read it easily.

Some times the absence of a rule is not that good.

But the strict use of a rule could be bad as well.

I have this little example:


I can say Matz is right to keep parentheses optional in Ruby, leaving to users the final decision on its usage.

Saturday, February 13, 2010

Ruby Symbols Ultimate Guide

In Ruby, a Symbol is a special class used to define a constant named label.

A symbol is defined using a colon ":" in the beginning.

Example:
:my_test_symbol

A symbol is not a string, but it has a string representation and an object identifier.

Ruby newbies ask about advantages on using constants over variables, or symbols over both, very often.

First of all, you must know there are no really Constants in Ruby. They are just a convention on variable names (starting with uppercase letters).

You can in fact, change the "constant" values along your ruby program.

That way, it is your responsibility to keep your Ruby "constants" with the same value almost all the time.



Strings, even with the same content are different objects, so, are identified differently.



So, strictly technically speaking, Symbols are pointers to memory objects containing the symbol name.

Differently from Ruby variables or even Ruby "constants", Symbol values could not be changed.



In fact you couldn’t even access the Symbol content unless through a Symbol#to_s method.



Remarkable points here are:
  • When Symbols are better then Strings?
  • Which are the advantages and drawbacks from one over the other?

If you have a few unique string values, and will use them the way they are (no concatenation, upper or lower case, no nothing), Symbols are the right tool for the job.

In any other circumstance, stick with strings. They are not that much slower then Symbols, and much more flexible.

Symbol scope is a bit different and need to be considered.



About performance, you need to have a few points in mind when dealing with a great amount of strings and Symbols:

About memory:

Strings are Garbage collected, Symbols are not.

So, Symbols will be there while your program is running, which can be a great memory consumer.

Have you ever considered how many objects you will have when you set a variable inside a loop?



When creating a great amount of Strings and Symbol, how did the operation compares in performance?



About CPU Time:

When you make Strings comparison rather then Symbols comparison, it could be a great CPU time consumer, since the comparison must be done for each character in the string.



Symbol "values" can be retrieved in many different ways:



Usage:

Symbols should be used whenever referring to a name (identifier or keyword), even if that name doesn’t exist in actual code yet.

  • Naming keyword options in a method argument list
  • Naming enumerated values.
  • Naming options in an option hash table.



That is it about Ruby Symbols