Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, March 30, 2011

The Problem With C++


C++ is my bread and butter language, the language I have spent the most time with, and language I know the best.  I've spent a great deal of time learning the ins and outs of C++, and its base language C.

  It is without doubt one of the most complex and powerful programming languages currently available, their isn't much you can't do in C++; procedural, object oriented, functional, meta programming.

  And the recent additions to the language, via C++ 0x, have further boosted its flexibility and power, from the succinct awesomeness of anonymous functions(lambda's) to the performance of R value references.  This is the language of the professionals, and the gaping maw that separates average Joe C++ programmer from the those that really know the language is vast. This is not Java, there has been, and hopefully never will be, any attempt to peddle to the legions of mediocre programmers.


 But despite my love for it, C++ has some serious defects.  Most of them stem from its C heritage.


 And the primary one is compilation times.  The C++ compilation model is archaic, it does exactly what C did, which is to copy and paste the contents of one file into that of another.  As the size of a project grows, the compilation times tend to grow exponentially.  C++ programmers have gone so far as to develop coding styles and even code patterns to reduce compilation types, this helps, but requires much extra time and effort, and in the end all it can really do is reduce the growth to something closer to linear.


 What the C++ committee needs to do is address this issue, and why they haven't already done so is beyond me.  Most modern languages do not take nearly so long to compile, for example D, a language much like C++, actually in many ways superior, but lacking widespread tool & compiler support, uses a more modern import system and avoids the C++ compilation nightmare.

 

JavaScript vs Lua


  I've used Lua  in the past, mostly as a scripting language embedded into games, but lately I've been doing some web programming which requires the use of JavaScript.

 The two languages are similar in their approach to OOP, which is prototypes not classes.  This takes some getting used to, if coming from a traditional class based language, but does offer some nice advantages.

 But I've started to notice aspects of JavaScript which seem glaringly inept when compared to Lua.


Advantage Lua:
1)  Lua "tables" are essentially equivalent to JavaScript's "object", yet tables are vastly superior as they offer both the functionality of a hash map and that of an array.  Additionally Lua tables can be keyed by any type, be it string, number or even other tables.  JavaScript is far more limited, the only thing that you can key "objects" by is a string.
  JavaScript offers a separate type called Array which allows you to do what you can already do in Lua with it's basic table.

2)  JavaScript has no functionality for importing code from one file into another.  Most people seem to resort to either creating a mega file, which contains all of their code, or just importing every file at the top of their HTML page.  This seems exceedingly crude to me.

3) LuaJIT is a custom virtual machine which gives Lua the best performance of any Dynamic language, even Google's V8 doesn't compete(over 2X as slow).  Huge advantage to Lua for this.


Advantage JavaScript:


 1) Now syntax wise I do prefer JavaScript, for as long as I used Lua I just never felt any particular love for the Fortran style of syntax, which requires excessive typing   JavaScript uses a syntax very similar to C, C++ etc. so most programmers will immediately be able to jump in.

2) Lua uses 1 instead of 0 as the base index into arrays etc.  This is out of sync with practically every other language in existence, and while not a major issue, it is something that should have been avoided. NOTE: you can use 0 if you want, it won't break, but most public code assumes a base of 1.



  Overall I currently feel that Lua is the superior language, and wish it were available for client site scripting of web pages.  Web programming seems to have evolved half-hazardly at best, and the only widely supported client side scripting language is JavaScript, so of course this is what I must use...

Web Host

 I've been dabbling around with web programming lately, so far just using HTML and javascript, but at some point I will need a web host, so I've been looking into various methods.

1)  Amazon EC2: Amazon's well known cloud computing service.  The cheapest model is called "Micro Instances" and costs $0.02 per hour, which translates into $14.5 per month.  Not so bad, although you do also have to pay for storage separately.
   EC2 is used by logging into your instance via remote desktop, so you have the freedom of running it pretty much however you want.


2) Google App Engine:  Google offers this alternative to EC2.  The nice thing about this service is that it is 100% free for up to 5 million page views per month.  It does force a certain approach to writing your server though, as you it can only be written in Java or Python and you have to use some specific Google API's for data storage.

3) Windows Azure:  Microsoft's cloud service.  Integrates well with Visual Studio, as they offer a plugin for it. The smallest instance they offer is still $0.05 per hour, over double the price of Amazon.  This seems to be the least appealing of the bunch for price, but does offer some integration with VS and .Net to make up for it.





 I think I'm going to try Google App Engine first, since well, it's free.