Tuesday, 19 March 2013

6 tiny productivity tips

These days are quite eventful here - therefore the time I can spend thinking or private-working has shrunk radically. Not saying it's bad, pretty much loving it. It's just the blog, that suffers from creativity. Next month I'm planning to talk about poetry. Just kidding. Technology is quite poetic already. So as I'm quite useless I thought I share 6 of my tiny mini productivity tips.

1 - XDebug tricks

I never start a day without XDebug. Like a doctor supposedly don't cut his/her patient as s/he feels like I guess a coder don't fix code without seeing its soul. Apart from all the general scenarios there are some special cases where you can apply some cleverness. Sometimes you don't know where a particular error happens. You see some variables are changed in the scope but no idea why. Here the problem is that the function stack represents a single state.

Here the red line represents what you see at a certain point in the stack trace. If there is any error it happened in the yellow area. I guess you see where it's going. By using a simply binary narrowing you can find the problem the quickest. Just add breakpoints in the stack trace to all function starts from the scope - one at a time and re-run the query. Also I've learned a cool trick from possibly the smartest guy ever I had the luck working with (Tamas) - by using conditional breakpoints that stops only when a certain condition occurs.

2 - Server environment indicator in prompt

One of the first thing I do on an external server is overriding the pompt. It's really hard to mess up a server by not knowing where you are - and it's mostly the production server where you delete the stuff. So it's always good to add a small string and set a different color scheme. Similarly you have the useful Environment Indicator module in Drupal as well.

3 - Test helper functions separately

Many times I have to add helper (utility) functions to a module. These functions usually deal with numbers, strings, array - things that are not really project but data structure related. Most times I create them separately in a single file with many tests. That makes it really easy to test without any distraction. And not to mentions it's much faster - you don't need to bootstrap anything else.

4 - Feeding the debug log to file

Besides inspecting the code with a debugger I do a lot of data dumps. Not that I like arrays and object attributes more than naked ladies - but still. However I don't like to distract the page with it. In Drupal's Devel module you have dd(). It creates you a drupal_trace.txt file in your OS temp directory (or else if you set it otherwise). Tail has a nice little flag: -f that keeps the stream reader open, so you can see your dumps real time.

5 - Wallpaper changes

Sometimes I don't like to check the time but it's still useful to check how much time I spend doing something. Those occasions I set my wallpaper to be rotated by every 5 minutes (or half an hour) - so when the background is changing I can subconsciously know that 5 minutes or whatever time spent by already. It helps me not to get lost in a task.

6 - Trace of everything

Just found this gem not long ago. In OS-X you have the Activity Monitor. It shows you the running processes, some analytics and you can kill as well. However you can be also curious what the glob is happening in the background. I thought you only can do it if you attach a gdb equivalent tracer to the process - but it turned out OS-X has something for you. Go to Activity Monitor, double click on the item and then click on the [Sample] button on the bottom-left corner. See the magic.



No comments:

Post a Comment