Shonzilla, a pattern-seeking animal

Life is a game of patterns and chance, and those who play well will win.

Feeds
Add to Technorati Favorites


Twitter

See also (via Entrecard)

programming coupons powered by RetailMeNot.com

Thu Apr 1

HOW TO: Prevent Mac apps to quit on you

Have you ever accidentally typed Command+Q (which is the standard Quit command on Mac OS X) instead of Command+W (standard for closing a window or a tab)?

I know I did… one time too many after which I googled for like 2 minutes and found how to fix this. Another 10 minutes later, here’s a digest with two concrete examples for all of you to peruse.

Mac software can store various settings in the so called Mac OS X user defaults system. Windows users may liken this to Windows Registry. It’s quite similar but somewhat easier to use. For example, you can access the defaults system from the command line using the full glory of command line tools which is exactly what I’m using here.

  1. Choose the application which quit shortcut you want to reconfigure (e.g. Chrome) and note down the text next to the quit shortcut (e.g. Quit Google Chrome
  2. Find the application’s domain in the defaults system by running this from the command line (with “-i” we’re ignoring case and finding this more quickly):
    defaults read | grep -i “chrome” 
  3. In the result to the command above look for the application’s domain which looks similar to internet domains only in reverse (e.g. com.google.Chrome)
  4. Now reconfigure the shortcut by using the application’s domain, the shortcut text and shortcut definition:
    defaults write com.google.Chrome NSUserKeyEquivalents ‘{ “Quit Google Chrome” = “@$Q”; }’
  5. Restart the application for the change to take effect.

In case you want to define a different shortcut, use the following special characters for using Command (Apple sign), Option, Shift and Control buttons:

@ - Command (Apple sign)
~ - Option
$ - Shift
^ - Control

After running all the above 5 steps correctly, you should have changed the shortocut for quit operation from Command+Q to Command+Shift+Q. Changes you make in defaults system will also remain active after restarting your Mac.

Here’s the similar change I’ve made on my Mac to prevent Eclipse from accidentally quitting on me (by redefining the quit shortcut to Cmd+Control+Q):

defaults write org.eclipse.Eclipse NSUserKeyEquivalents “{ ‘Quit Eclipse’= ‘^@Q’; }”

To assign Quit Eclipse shortcut to Cmd+Shift+Q you would need to escape $ sign because of the way shell parses the command line (to access reference environment variables and command parameters):

defaults write org.eclipse.Eclipse NSUserKeyEquivalents “{ ‘Quit Eclipse’= ‘@\$Q’; }”

Other signs you do not need to escape.

Wed Jun 10

Extended code folding in Eclipse

The problem

I program Java. I use Eclipse to do it. I like concise code. I work with open-source projects. Sometimes I need to read someone else’s code. Sometimes (more so than not) people write ugly code or hard-to-read code at least. When I say “ugly” and “hard-to-read” I usually think of long methods.

Is there a solution?

If you fit the above description then you might want to use code folding. If you had a fair share of navigating through code, you probably already know about it. In a nutshell, code folding is an IDE feature which allows you to collapse (and later expand) a block of code that you do not want to look at all the times, thus leaving more screen real-estate for looking at code that matter to you at a given moment. Sounds useful? Well, it is!

However, you may not be happy with the code folding support bundled with Eclipse since it works with (nested) classes, methods but does not work with control flow structures (if, while, for, try-catch-finally, etc.). This full-blown code folding support that includes any code block including control flow structures I call extended code folding. You may have seen NetBeans and other IDEs sporting this feature and you wished you had it in Eclipse, your favorite IDE.

Solution indeed

Well, there’s a solution for this missing feature in the form of Eclipse plugin called Coffee Bytes Code Folding over at RealJenius.com. All you need to do is add the following update site:

http://eclipse.realjenius.com/update-site
Once installed go Preferences->Java->Editor->Folding and in Select folding to use drop-down menu choose newly installed Coffee Bytes Java Folding. This plugin, just as Eclipse’s built-in code folding support, allows you to see the folded code by hovering your mouse over a plus sign. While I’m there, let me suggest you to turn on line numbers via Preferences->General->Editors->Text Editors->Show line numbers as it will make it easier to not only recognize folded code sections but also to tell what line are you looking at without actually having to click at the precise line in code and read the number from status bar. This is good for linking compiler/run-time errors and what line your colleague is talking about with less effort in exchange for some 20-30 pixels. I also recommend using Modern icons for plus/minus folding handles so that you can easily distinguish whether you’re using extended or built-in code folding.

After using this plugin for a couple of minutes, I’ve noticed one thing I didn’t like. When a code block is folded, braces (a.k.a. curve brackets) are not hidden as they are with the built-in Eclipse code folder. Namely, the closing brace remains standing in a separate line thus needlessly wasting one line without providing any meaningful information.

Shortcuts

Shortcuts are your friends as they reduce the distance your mouse (and your hands) need to move (and programmers should do everything they can to avoid RSI). Also, each shortcut you learn improves your ninja skills. You may want to learn them:
  • Ctrl + <Numpad Plus> - Expand a single node
  • Ctrl + <Numpad Minus> - Collapse a single node
  • Ctrl + <Numpad Multiply> - Expand (toggle) all nodes
  • Ctrl + <Numpad Divide> - Toggle folding (turn code folding on and off)
  • Ctrl + Shift + <Numpad Multiply> - Reset structure
  • Ctrl + Shift + <Numpad Divide> - Collapse all

Final thoughts

This plugin will also allow you to define custom regions (as Microsoft Visual Studio .NET has had since first version), which Jeff Atwood (of Coding Horror and StackOverflow fame) calls glorified comments with which I fully agree. Having that in mind and understanding that “folding is used to sweep code under the rug” in mind, you should really use code folding ONLY on other people’s code that you have no control over. At the same time, you should make sure that you do not fold your own code as you may be led to believe your code is easy to read and you’ll end up creating horribly long methods and code blocks that are hard to read. Well it will be hard to read for people not using code folding, which are many. After all, nobody should be force-fed with a bunch of crutches plugins anyway. :-)

Conclusion (and a pattern)

So what’s the takeaway here? It’s a pattern to keep in mind:
If code requires code folding, that code must be bad.
Why do I say this? Because folded code hides what’s inside thus violating Separation of concerns principle since folding hiding code may lead you to squeeze all kinds of logic inside a single folded line.

Sun Mar 22
Sun Jan 25
[Flash 9 is required to listen to audio.]

The meme of “4-hour work week” (heavily promoted by Tim Ferriss and his book bearing that name) strikes me as curious enough to react when I hear an original comment on the subject of work vs. fun vs. pastime.

This subject provoking many questions like:

  • What is work?
  • Is it good not to work?
  • What kinds of work can someone else do instead of you? or What kind of work can really be outsourced?
  • What is the goal in not working? (perhaps, you should define work first)
  • Why does the work need to stop before fun begins?
  • How much or how little can a human being work before going insane?
  • Do you believe someone saying “Yes, I’m surfing the Net. I need it for work.
  • Do you believe someone telling you “Can’t talk now, I’m working!” is telling the truth every time?
  • Is this guy Tim Ferris really lying (pun intended) in net bed between two palms during his 36 non-work hours of the week and not working?
  • … any many others.

Probably answers to these questions would vary more than you think from person to person. What would you say?

Book Cover

I personally think that internet and shortened attention span has brought on a slew of misleading titles (of books, blogs and newspaper articles and beyond) that promote a (theoretical) possibility getting things done with ridiculously little effort or with amazingly little time. Some examples from some of my fields of interest: Teach Yourself Programming with Java in 24 Hours, Teach Yourself C++ in 24 Hours, Teach Yourself Spanish in 24 Hours, Teach Yourself Javascript 1.3 in 24 Hours, etc.

Regardless, you may want to listen to this parody called “14-second work year” that ridicules the 4-hour work week beyond belief. Yes, it goes overboard, but it also puts things into the perspective. The source of this audio - QPR (Quotidian Public Radio) is a parody in its own right of NPR (National Public Radio). :-)

NOTE: If you’re not very familiar with Tim Ferriss and/or you haven’t read his book “4-hour work week” You may also want to read bio before listening to the “14-second work year” story of Jim Fairness from this parody.

Fri Jan 9

Is 4-hour work week a myth?

Today I’ve read an interesting blog post that some may even find controversial - “5 Time management tricks I learned from years of hating Tim Ferriss”. Tim Ferriss is the author of a bestseller called “The 4-hour work week”.

Although the blog post may appear to review of Timothy Ferris as a person and his infamous book, it actually extracts the really useful time management tips:

  1. Don’t hang out with people who don’t respect your time
  2. Cut to the chase: Tell people who are full of sh*t that they’re full of sh*t
  3. Self-centered people are more likely to waste your time
  4. Productivity is about meeting your goals, not getting out of doing work
  5. Time management is about making time to connect with people
and raises some interesting questions like what do we label work nowadays?.

Book Cover

In the case you have read the book, you’re planning to read it (or listen to it), you have heard of the book or you’re just plain curious - make sure you read the this rant by Penelope Trunk. Penelope’s post is actually a great reality check for all those Generation Y-ers who are subjected to:

  • vast amounts of information online (we all are, but it’s their default mode - some people believe Gen Y = Net Generation),
  • an unsurmountable quantity of choices, both on-line and (less so but still) off-line that necessarily come with it,
  • (insert your favorite challenge of the new economy here)
  • and the difficulty to tackle it all.
Indeed, after realizing witnessing all these challenges that we all face, people - , especially young people - pose the perennial question:

How do I tackle and enjoy my life, since I cannot escape it?

This is where Tim Ferriss and his book jump in and find the target audience. Tim and his book have it as their goal to heal this great wound that goes along the so many (insert your urge), so little time.

Do not get the impression that I’m dissing Tim Ferriss’ book since offers some interesting insights. If you manage not to get distracted by his you can get some useful tips, get amused by some of his experiences and, if you’re lucky, even his literary style.

I always had respect for people like Tim Ferriss (whilst managing to avoid being jealous) in the respect how motivated they are to try things out and succeed in many some of them. It’s the of respect for all the people who manage to make up work, make it fun to do and, thanks to skills and personal traits a small number of people have, who are able to do things that othermost people crave to do. I believe the truth is the following: unless you’re born with the appropriate skills and personal traits (having a fortunate family situation and great people people to look up to can only help) you’ll find it rather hard to make up for what you do not already have. Tim Ferriss’ book may entertain you and give you a short-term motivational boost but it won’t rewire your brain, change your value system nor your improve your social skills, mental capabilities, or dancing skills.

In the end, work has made us what we are. It’s the work, coupled with creativity, that has fueled the human evolution making it faster every year. To prove the correlation, there are plenty examples of people dumbing down because they do not work. Rarely, the opposite happens or, even more rarely, someone makes a fortune out of a seemingly stupid ideas.

If I would correlate the lifestyle Tim Ferris is advocating with work, there’s an emerging pattern, something worth considering and something I advocate as well: switch jobs goals - do not allow to get bored and bogged down because life is too short. Apart from keeping you on the edge, makes you feel stimulated, energized and alive, such lifestyle also appears to speed up evolution.

What do you think?

Thu Oct 16