Friday, October 28, 2011

TRouBLe is Useful

Web programmers have probably seen this a lot:
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left:20px;

The reason many programmers "need" 4 lines of code for such a simple thing, is that it's impossible to set the margin (margin is just an example, since this is also true for padding/border/...) to 20px, and then override just the top margin. But isn't there a better way?

Well, there is a shortcut for the above:
margin: 10px 20px;

Shorter, heh?
The parameters for attributes such as margin, are specified in this order: Top Right Bottom Left, or TRouBLe for short. CSS parsers are smart enough to apply the last specified parameters, to those that were omitted. So in the above example, I've omitted bottom and left, so the 20px value would be applied to those as well.
The general rule is:
* if only one value is specified - it is used for all (top, right, bottom and left)
* if two values were specified - the first will be used for top and bottom, and the second for left and right
* if thee values were specified - the first will be used for the top value, the second for the left and right values, and the last for the bottom value
If I wanted to set the margin-left to 10px, I'd have to write this "long" statement:
margin: 10px 20px 10px 10px;
Which is still shorter than the first example above.
Many times, the shortened syntax can be used, and save us some typing while increasing the expressiveness of CSS attributes.

EDIT: It seems I messed up a bit the order in which things are shortened. Thanks for Tomer for correcting me. I've updated the post accordingly.

Wednesday, October 26, 2011

Installed Apps Doesn't Show in Market

Today I noticed an annoying bug in the Android Market application: it showed only 3 applications under the "my apps" section in the market, even though I have over a couple of dozen installed.

Rebooting the device or removing the SD card didn't help.
Being rather new to Android, I was tempted to remove the market application, and reinstall it. But Android is much like Linux, and much less like Windows, so reinstalling an application would probably retain the old settings.

And then it hit me - the settings. Why not reset those?

Simply go to: settings -> applications -> manage applications -> market -> clear data
That's it. The next time the market app launches, it will rescan the installed applications, and everything will be fine again.
That's pretty robust, even though it's in a geeky way, since I don't expect most people to do that.

Friday, October 21, 2011

Best Windows Development Environment

I know, this one is going to sound a bit crazy, but hear me out. IMHO, the best Windows development environment is Linux.

First, let me start with a less surprising statement: the best way to run a Windows installation is on a VM. This should make perfect sense to anyone who runs Windows on a daily basis, and knows that as time goes by, it simply gets slower.
No registry or other cleaning utilities can return it to run as fast as it was the day you installed it.
Moreover, when one wants to test a new piece of software, the VM's snapshot feature really shines.
So, every once in a while, one can revert to the a stored snapshot, and get an almost fresh Windows installation, almost instantly.

When it comes to development environments, where one rarely install tools, and the code is managed in source-control, reverting to a snapshot is even easier.

My second point is: use the host environment that you feel most comfortable with. In my case, it's Linux. Specifically Ubuntu. If you prefer running a Mac or a different Windows as the VM guest, it's OK as well. But I can assure you that after giving Linux a trial period as the host OS, you'll find it the most pleasant one.

Moreover, if cross platform compatibility is an issue for you, having Linux *and* Windows running simultaneously, is a great advantage and a real time saver.