Why C++ will not die

If you work with programming, from time to time you will see articles talking about the inevitable downfall of C++ as a main programming language.  Some people go as far as to say that C++ is even harmful to your career and that you should avoid using it whenever possible.

Despite the reasons why some people dislike C/C++, I believe that the backlash against C and C++ is rooted more on lack of understanding than on real fact.

The Case for C

C was created to be a language for professional programmers, not for people that are still learning the trade. The designers of C created it as a means to efficiently develop operating systems. One of the consequences of this design is that C is as close to the hardware as one can get without using assembly itself.

This may be bad if you are just starting, but it is liberating if you are a seasoned programmer that really wants to get the most out of the machine.

If you look at the criticisms against C, the most important arguments are that it makes it easy for programmers to shoot themselves on the foot. No wonder, C was created exactly to make such things possible.

Writing Simple Programs Quickly

If your goal is to write small programs easily, you should stop your criticism of C. The fact is that for writing small, simple programs C doesn’t count. Such programs should be written in Perl, Python, or whatever flavor of scripting language is the most popular at the time. This is what UNIX programmers have done forever. 

For small programs that impose no bottleneck on the system any language is OK, as long as it makes it easier to solve the problem at hand. Lisp and Prolog are excellent to solve symbolic problems, for example. Quick file processing can be solved with Perl.

Large Scale Programs

Now, let us talk about the programs that really matter in each platform, i.e., large scale software that imposes a bottleneck on the machine.

In higher level languages, such as Pascal, Java, or Lisp, one is working with protective gear that allows them to be sloppy without sacrifice of safety. This is not to say that one cannot write efficient programs in Lisp, say, but doing this is harder than usual.

In a language like Lisp, if you want to write efficient code you need to understand all sources of bottlenecks. This usually means you have to understand how your particular system is implemented and how the underlying architecture works. Then, you need to find ways to avoid such bottlenecks, and doing this usually means going to a lower level of programming such as (guess what) rewrite you program  in C or assembly (or maybe using typed expression in Lisp, which is just another way of thinking in assembly).

In other words, you have to be really expert in the language, in the implementation of the language, and in the underlying machine in order to write something out-of-ordinary. And if you have the knowledge to do this, it might be easier just to write everything in C. On the other hand, while you may need to do this just in a few cases on the whole program, the bigger your program is the higher the chances you will need to go lower level more frequently. This is why writing a web browser or an operating system in anything else other than C/C++ is such a difficult proposition.

Now compare the situation with C. Sure, you cannot expect that a novice programmer will know how to handle pointers or null terminated strings. That is fine, though, because C was not made for them. The C language was created as a vehicle to write efficient software for people that care enough to use such a tool.

Notice, however, that once you master a few concepts you can treat C as just another high level language, but one that matches closely to hardware concepts like real memory addresses. Maybe you will lose the illusion of objects, for example, but you will gain a real ground on what happens in the computer.

What about C++

I talked a lot about C, but what about C++?

C++ is the child of C that was adopted by the industry. C++ has everything that the industry likes about a technology: it has buzzwords, it is constantly changing and requiring new tools and compilers, it has strong support from big companies like Microsoft, and it  has a lot of legacy code.

The legacy issue with C++ is so important that C++ has essentially killed C as a commercial product. You don’t buy nowadays a C compiler, you by a C++ compiler that can also compile C code. In this sense, C++ is really important, because it is the only way C programmers can continue using C.

Also, despite the many problems with the extensions created by C++, many of them are really useful, such as namespaces, a standard library of containers, and basic support for objects. So, basically all commercial installations of C++ can use C and pick-and-choose the features from C++ that they want (see for example Google’s style guide for C++ [2]).

In conclusion, although a lot of people don’t love C/C++, it has an important role in the industry that is not been filled by any other language. This probably means that we will continue to see good C++ programmers making money and working on interesting projects in several areas.

Further Reading

Many of the advantages and disadvantages of C++ for large scale programs are listed on  Large Scale C++ Software Design, by Lakos.

An even deeper description of C++ model is given in Inside the C++ Object Model, by Lippman.

[1] http://www.ittybittycomputers.com/IttyBitty/CppHarm.htm

[2] http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

Using Firebug to Edit HTML

Some time ago I started playing with Firebug, a Firefox extension, that provides tools for editing and debugging html and Javascript. It is a tool that I recommend to anyone interested in creating web content.

The core of the extension is a window that allows one to inspect the HTML, CSS, and Javascript in a web page. With this efficient tool you can highlight, make small changes, or even write parts of a web page until it is as good as you want it to be.

Firebug is the closest I have seen to a true HTML editor, that is, something that allow you to play with HTML code in real time. While a lot of HTML editors will provide the necessary ways to enter HTML code, it is not the same as having the browser updating at each stroke.

The only inconvenience of Firebug as an HTML editor is that it will not allow you to automatically save the edited content to a file. This make the process less smooth, because you need to save yourself the document.

Despite this small problem, it is actually easy to save a page that has been edited with Firebug. Just select with the mouse the elements of the page that have been edited. Then, select copy from the context menu. You can now save that text to a suitable editor or modify the previous html/css file.

Firebug provides a lot of flexibility for website writers. It is a great tool that can provide invaluable work for anyone that needs to create web pages.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

Google changes its approach to China

In a change of their current policy of providing filtered content in China, Google has decided to stand against the Chinese government and remove all filters on their search results. The reason mentioned for their policy change was a grave web-based attack against the accounts of human rights leaders.

I think that this is a honorable decision, and all free countries should support such an initiative that aims at making the web more democratic. After all, I think that if we can’t make the whole world a democratic place, we can at least try to do the right thing with use of technology.

See the full announcement in the Google blog.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

First Impressions of Google Wave

Google wave was introduced in the last I/O conference (2009) by Google as  a new platform for communication. A platform using web 2.0 concepts, and providing an array of features that has not been available in other platforms.

I received an invitation to use Google wave and decided to take a quick look. Although some of the features of the product are impressive, there are more than a few that are annoying, so I don’t know if the future of this tool is so interesting anymore.

  • Speed: I found the performance of Google wave to be less than desirable. Searches (especially for public documents) take a long time. Loading of documents also take a lot of time. Maybe this could be solved by showing only small parts of a wave instead of loading everything.
  • Interface: the interface is unconventional. While one may get used to it after some time, it is difficult to new users to navigate. Compare this with a web site like twitter, that is easy for anyone to understand.
  • Extensions: there is an extensions protocol that allow programmers to create new functionality. However, I found it hard to find information on how to use these extensions effectively. Even installing extensions is not so clear at the beginning.
  • Compatibility: I expected that you could integrate Google wave seamlessly to Gmail and Gtalk at least. It doesn’t seem to be so. I am still trying to make this work.

It looks like Gwave would be interesting for a group of people that decided to collaborate on the platform. But I think that integrating email and other tools into Google wave is more complicated than it should be. Or maybe I just didn’t get it — but if that is the case there is a lot of people currently in this situation.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

How to Create a Duplicate Row in Oracle

When working with Oracle databases, it is sometimes interesting to create a duplicate row of a table. Most of the times this happens when I am testing something on an application and need to tweak one of the entries in a table.

There is a standard SQL trick to duplicate elements of a table that can be used in an Oracle database. I am showing this here because it can be of interest for other people that have the experience of working in an Oracle environment.

The basic idea behind this technique is just to create a temporary table that will hold the data only during the time necessary to make the required modifications. Since the table is created immediately, the inserted content will make the table have all columns of the original table.

Suppose that the following returns non null:

select * from myTable where myKey=8572

Then the required code looks something like the following:

EXECUTE IMMEDIATE
CREATE TABLE temp_table AS SELECT * FROM myTable where myField=8572
UPDATE temp_table SET anotherField='AA'
INSERT INTO quote SELECT * FROM temp_table
DROP TABLE temp_table

With this simple trick one can duplicate any row and modify it to hold the required values.


Further Reading

A comprehensive book on Oracle is Oracle Essentials by Greenwald et al. Here is another Oracle book that is worth reading to get a better idea of how it works.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter