Monday, December 24, 2012

3G, social networking and work

I recently and grudgingly upgraded my cellular internet to 3G. Actually 2G sufficed for most of my needs which was basic document editing and emails. Add a bit of web browsing and Facebook, Twitter. All that was doable on 2G and if I used my cellphone - should say smartphone, but it's WP7.5, and I like calling phones as cellphones - as a hotspot then with some patience I can even get some work done. What I can't do is access online banking. By the time the applets load the session expires.
So back to 3G, the first thing I noticed was the speed. I'm not a speed junkie but the speed made me find a speed test app and check it out. And by God, I got 5 freaking mbps down and 1.6mbps up. I have never browsed web at such speeds. Things snap up like lightening and coupled with IE the whole browsing experience felt like turbocharged. Another area was the Facebook and twitter integration. The info in people hub, updates on posts and communications would load spontaneously. It has been exhilarating for me using 3G and even though I have to shell out INR 252 ~= $5 for 1GB, I feel like for the speed its worth it. Hmmm, maybe they should show users browsing on 3G as compared to 2G in the ads. That would show most people what we are missing.
Next is social networking and I can say that Facebook has helped get in touch with many of my old friends - school friends with whom I had lost contact. So social networking is in full gear these days.
Also on a side note IM+ is helping me greatly with chat. Well, one life saving app on wp7.5!
Lastly about win8, I've been using it regularly for some time now and my outlook about it hasn't changed much. Using it on a touch screen is probably going to be much better than using it on a vanilla laptop. So I guess I have done all to see if win8 has any use for me. And I'll be going back to win7 soon. Don't think there's anything on win8 that I'm gonna miss, maybe the task manager but I should get something like that for win7 too!
That's ot from this side of planet. Adios!

Saturday, December 22, 2012

What we are doing for ages need not be the best thing that we are doing

Original Source:

What sorts of things should you (or should you not) put in a C language .h header file? When should you create a header file? And why?
When I talk to embedded programmers about writing device drivers or using real-time operating systems or my Embedded C Coding Standard book, I often come to see that many lack basic skills and information about the C programming language. This is probably because we are mostly a gang of electrical engineers who turned to programming and are self-taught in C (and C++ and the myriad other programming languages we make use of).

Dos and don'ts

In the interest of promoting the general welfare, I'd like to use this month's column to discuss one of those basic skills that is too often lacking: building proper header files. Here's my list of Do's and Don'ts for embedded C programmers to follow when creating .h header files.

DO create one .h header file for each "module" of the system. A module may comprise one or more compilation units (e.g., .c or .asm source code files). But it should implement just one aspect of the system. Examples of well-chosen modules are: a device driver for an A/D converter; a communication protocol, such as FTP; and an alarm manager that is solely responsible for logging error conditions and alerting the user of the active errors.

DO include in the header file all of the function prototypes for the public interface of the module it describes. For example a header file adc.h might contain function prototypes for adc_init(), adc_select_input(), and adc_read().

DON'T include in the header file any other function or macro that may lie inside the module source code. It is desirable to hide these internal "helper" functions inside the implementation .c file. If it's not called from any other module, hide it! (If your module spans several compilation units that need to share a helper function, then create a separate header file just for this purpose.) Module A should only call Module B through the public interface defined in moduleb.h.

DON'T include any executable lines of code in a header file, including variable declarations. But note it is necessary to make an exception for the bodies of some inline functions, about which more below.

DON'T expose any variable in a header file, as is too often done by way of the extern keyword. Proper encapsulation of a module requires data hiding: any and all internal state data should only be in private variables inside the .c source code files. Whenever possible these variables should also be declared with keyword static, which will enlist the linker's help in hiding them.

DON'T expose the internal format of any module-specific data structure passed to or returned from one or more of the module's interface functions. That is to say there should be no "struct { … } foo;" code in any header file. If you do have a type you need to pass in and out of your module, so client modules can create instances of it, you can simply "typedef struct foo moduleb_type" in the header file. Client modules should never know, and this way cannot know, the internal format of the struct.

Inline functions

On a related note, I recently received this question from an engineer in Brazil:

"I am trying to conform to the rules in your Embedded C Coding Standard book and I just ran into what may be a problem with Rule 6.3.a. Instead of using function-like macros, I'm using inline functions, as you recommend. However, my compiler (avr-gcc) gives an error when I declare a function to be inline at both header and source file. If I put both the inline declaration and function body inside the header file it works fine. This fixes my compiler problem, but isn't it a bad practice to place code inside the header file?"

This is a good question, as it seems at first to be about a conflict between my bug-killing rules and something else I refer to as "Generally Accepted Programming Principles" (i.e., GAPP).

The inline keyword is a part of the C++ programming language that was added late to C (in C99). In C++, most programs are built out of classes–with GAPP dictating one header file per class definition. Any C++ function may be declared inline. However, if the inline function is a public member function (a.k.a., "public method") of the class it is necessary to place the code for the inline function in the header file. (This is so that all of the other modules that use the class can see the code they need to have placed inline by the compiler.)

Of course, placing the body of any function inside a header file conflicts with GAPP for the C programming language. Here's a set of rules to help you decide where to put the code for inline functions in C.

IF the inline function is a "helper" function that's only used inside one module, THEN put it in that .c file only and don't mention it in the header file. This is consistent with Rule 4.2.c of my Embedded C Coding Standard, which says that "The header file shall identify only the [functions] … about which it is strictly necessary for other modules to know."

IF, however, the inline function operates on the abstract data type defined in the header file and must be visible to two or more modules, THEN put the body of the inline function inside the header file. There is no rule in the Embedded C Coding Standard that strictly prohibits this, so there is no conflict after all.

Though not really specific to embedded software development, I hope this advice on good C programming practices is useful to you. If it is please let me know and I will provide more C advice like this in future columns.

Michael Barr is the author of three books and over sixty articles about embedded systems design, as well as a former editor-in-chief of this magazine. Michael is also a popular speaker at the Embedded Systems Conference, a former adjunct professor at the University of Maryland, and the president of Netrino. He has assisted in the design and implementation of products ranging from safety-critical medical devices to satellite TV receivers. You can reach him via e-mail at or read more of what he has to say at his blog (

Wednesday, December 12, 2012

Windows 8 and Elementary OS 0.2

Three months ago my current workstation was a slow hulking monster. It was taking forever to boot and literally crawling in between reboots.
I was frustrated with Ubuntu. Unity was the synonym for awkward desktop that tires you just using it. It was like my $4 Blues headset that was a pain over the ears despite its above average sound. Startup of over 1 minute and shutdown of another minute. Add to that I wasn't able to use sleep with Ubuntu - mostly it would screw up WiFi and sound. On a bad day it did hung my lappy into permanent sleep. Had to remove the battery to revive it. So no trusting it. Lots of wishing that someone would fix it, but even after 4-5 iterations and the sleep remained just the same deadly. ScaryBuntu!!!
Windows 7 has also aged quite some and it was also acting up like an old crone that has all the youth sucked out of it. Truth is Windows 7 was the best of all windows. It was stable, it worked, didn't ask you for crap that you don't give a damn about. But then you load a crapload of programs on it and invariably it starts showing. It takes 2-3 minutes to boot and if you need to shut it down then it goes 3-4 minutes. It especially sucks if you switch between OSes as often as I do being multi-platform developer.
So the quest was to setup something that would be light to boot and faster than the aged horses I had on my hands. I found one half of the pair in the form of elementary OS. I started with the developer build, tested it for couple of weeks on my hardware and found that it actually kicked major ass. So after some tweaking and murmuring prayers and of course some crashes I had half the base covered. I have upgraded that build twice since then, the latest being Luna Beta. Its just awesome. Starts in about half a minute and shuts down in 4 seconds flat.
The second wheel for last 3 months had been win 7 - the aged horse and it had been dreadful. So I quickly got my hands on the Win 8 pro version to see how much kick ass it is. I had read a bit about Win 8 and it has received attention as well vista like praise too. But one thing I came to know that it's supposed to be faster than win 7. In fact supposed to be a lot faster than win 7. So with all these expectations and hope I installed it. The experience has been mixed bag so far.
#1 Win 8 is only marginally faster than Win 7. I have startup times averaging half a minute for a laptop with Pentium B960 processor and 2 GB of RAM. Mind though, no heavy programs yet. And shutdown times are also around half a minute which tells me that when I go full on assault on applications this windows is also gonna crawl.
#2 The supposed to be Not-Metro Apps and NEW Start menu or screen whatever MS calls this. Looks like a gimmick. It as the only interface would make more sense on a tablet. On a desktop its just confusing. And it takes more time to browse for apps. Luckily application search is something that MS got right. So I'm using Unity like keyboard searches for apps. The whole UI seems kinda half-ling. There are some metro elements popping up on desktop here n there. The dialogs appear faster and the animations are great eye candy. But it all feels inconsistent. And this inconsistency is present everywhere. We have a metro settings app as well as control panel. And the stuff is divided between the two. That's kick ass confusion.
#3 Some small life saving touches. Upgraded windows explorer. New copy dialog with pause button. New metro style task manager. Hot corners are better on a tablet or desktop with mouse. On a laptop they are pain in the arse to use.
#4 Can a desktop and tablet UI be ever merged?
Its a million dollar question. Tablets are completely different than computers. They are held near eyes. They are handhelds while a desktop is not. You need to approximate the user input considering finger input for tablets while on a desk top user typically has finer control using mouse. On a laptop also a touchpad works pretty well. The so called touch mice are a gimmick. For most users these gestures mean more learning and complexity. I don't  want to generalize but yours truly has never bothered with gestures in all the browsers. I personally like clear easy to access menus and a UI which is WISYWYG. This Thing about discovering things would suck for general users. Because most of them tend to overlook what's presented to them right in front.
From workflow point of view Win 8 doesn't cut it. Its not intuitive. It feels like MS should have gone with a separate touch shell. But only time and the general user will tell what is to stay and what not!!!

Sunday, December 9, 2012

Day Counter

I wanted to code something small to count days to a particular date from today. So I coded a small app in .net and found it very useful. It's done in about an hour so doesn't have much in terms of functionality. It has the target date hardcoded. But then again considering it's limited scope I didn't go to any more trouble for adding more functionality.
Later I tried to do similar things in Qt and succeeded somewhat. There are couple of differences in both apps in that Qt version has colours used for numbers and text. And I have also included past targetted date display functionality in Qt version too. In this case before target date it shows Remaining Days while after target date it shows Past Days.
The links are as follows:
.Net Project
Qt Project

Saturday, December 8, 2012