Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
C++ and Perl - why did they do it THAT way?

"Why did [they] do it THAT way?". It's a question often asked by the brighter and more perspective delegates on courses concerning some features of a language that I'm teaching them. And the answer "because they did" is a poor one. It's like saying to a child "because I said so" rather than looking behind the scenes for a real reason.

C++ builds up on top of C, and maintains the C syntax. So there are many things in C++ which, had it been written from a clean sheet, might not have been included. And C++ is a low level language with bit / byte / register control capability, so some of the constructs, capabilities and syntax is somewhat more cumbersome than would be ideal for many modern applications. Which is precisely why it's still much used in computation intensive type works and device drivers, etc, but has been displaced by Java and C# for many of the more mainstream uses - Java and C# both take the philosophy and approach of the C++ syntax, modifying and extending it to remove the low level and C compatibility, and other complexities who's implementation costs outweigh their usefulness in the mainstream. It's little wonder that Java and C# look very similar to each other, then, with the same starting point and same philosophy and the same market.

Perl's another language where "Why is it done THAT way" is an excellent question that is, from time to time, answered by a rather glib "for historic reasons". The use of @ as the special character to signify a list would probably NOT have been the decision made after email addresses became common, but it was an excellent choice at the time. But many (most) other answers to "why was that provided" in Perl cam come down ro a far, far better answer.

Why use \s \d and \w to represent space, digit and word characters in Perl regular expressions? Because they're very quick to type and you can get a whole lot of code in a little space ... because the \ is already designated as the 'escape' character for strings and regular expressions, and because s d and w stand for space, digit and word. But why go on to use the capital equivalent \S \D and \W for a non-space, non-digit, non-word? Now that one stumped me the first time I was asked, but I can now ask you back "what better suggestion do you have?". In practise, using the same letter in capital and lower case makes them very easy to remember once you're used to them. And the resultant regular expressions are short and elegant.

Of course, Perl is eclectic ... so you can, if you prefer, write [[:space:]] for a space character and use all of the other posix standard regular expression handlers too.

This week started with me teaching OO programming in C++ and is ending with me teaching OO programming in Perl (on our Perl for Larger Projects course). And the two philosophies and approaches make an interesting comparison. Both are right for the right application ... both are great languages and what a great deal of fun I've been having.

A series of C++ examples that put together a whole host of the facilities offered by C++ - inheritance, static, inline, public, private, const, friend, vector, namespace, new, overriding, overriding operators ... was written on the fly, and I've posted them up under our putting it all together modules. I don't have the same Perl examples to show you, as that course has still got a day to run but of course you'll find plenty from previous courses in places such as "more object in Perl" resources.
(written 2006-11-16, updated 2009-01-01)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C231 - C and C based languages - Introduction to C++
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3052] Getting your C++ program to run - (2010-11-15)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [2169] When should I use OO techniques? - (2009-05-11)
  [2004] Variable Scope in C++ - (2009-01-22)
  [336] Targetted Advertising - (2005-06-05)
  [318] Choosing a theme - (2005-05-20)
  [317] Programming languages - a comparison - (2005-05-20)

P208 - Perl - Lists
  [3939] Lots of ways of doing the same thing in Perl - list iteration - (2012-12-03)
  [3906] Taking the lead, not the dog, for a walk. - (2012-10-28)
  [3870] Writing more maintainable Perl - naming fields from your data records - (2012-09-25)
  [3669] Stepping through a list (or an array) in reverse order - (2012-03-23)
  [3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
  [3400] $ is atomic and % and @ are molecular - Perl - (2011-08-20)
  [2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
  [2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27)
  [2813] Iterating over a Perl list and changing all items - (2010-06-15)
  [2484] Finding text and what surrounds it - contextual grep - (2009-10-30)
  [2295] The dog is not in trouble - (2009-07-17)
  [2226] Revision / Summary of lists - Perl - (2009-06-10)
  [2067] Perl - lists do so much more than arrays - (2009-03-05)
  [1918] Perl Socket Programming Examples - (2008-12-02)
  [1917] Out of memory during array extend - Perl - (2008-12-02)
  [1828] Perl - map to process every member of a list (array) - (2008-10-09)
  [1703] Perl ... adding to a list - end, middle, start - (2008-07-09)
  [1316] Filtering and altering Perl lists with grep and map - (2007-08-23)
  [1304] Last elements in a Perl or Python list - (2007-08-16)
  [968] Perl - a list or a hash? - (2006-12-06)
  [773] Breaking bread - (2006-06-22)
  [762] Huge data files - what happened earlier? - (2006-06-15)
  [622] Queues and barrel rolls in Perl - (2006-02-24)
  [560] The fencepost problem - (2006-01-10)
  [463] Splitting the difference - (2005-10-13)
  [355] Context in Perl - (2005-06-22)
  [240] Conventional restraints removed - (2005-03-09)
  [230] Course sizes - beware of marketing statistics - (2005-02-27)
  [140] Comparison Chart for Perl programmers - list functions - (2004-12-04)
  [28] Perl for breakfast - (2004-08-25)

P212 - Perl - More on Character Strings
  [3927] First match or all matches? Perl Regular Expressions - (2012-11-19)
  [3707] Converting codons via Amino Acids to Proteins in Perl - (2012-04-25)
  [3650] Possessive Regular Expression Matching - Perl, Objective C and some other languages - (2012-03-12)
  [3630] Serialsing and unserialising data for storage and transfer in Perl - (2012-02-28)
  [3546] The difference between dot (a.k.a. full stop, period) and comma in Perl - (2011-12-09)
  [3411] Single and double quotes strings in Perl - what is the difference? - (2011-08-30)
  [3332] DNA to Amino Acid - a sample Perl script - (2011-06-24)
  [3322] How much has Perl (and other languages) changed? - (2011-06-10)
  [3100] Looking ahead and behind in Regular Expressions - double matching - (2010-12-23)
  [3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
  [2993] Arrays v Lists - what is the difference, why use one or the other - (2010-10-10)
  [2877] Further more advanced Perl examples - (2010-07-19)
  [2874] Unpacking a Perl string into a list - (2010-07-16)
  [2834] Teaching examples in Perl - third and final part - (2010-06-27)
  [2801] Binary data handling with unpack in Perl - (2010-06-10)
  [2657] Want to do a big batch edit? Nothing beats Perl! - (2010-03-01)
  [2379] Making variables persistant, pretending a database is a variable and other Perl tricks - (2009-08-27)
  [2230] Running a piece of code is like drinking a pint of beer - (2009-06-11)
  [1947] Perl substitute - the e modifier - (2008-12-16)
  [1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
  [1727] Equality and looks like tests - Perl - (2008-07-29)
  [1510] Handling Binary data (.gif file example) in Perl - (2008-01-17)
  [1336] Ignore case in Regular Expression - (2007-09-08)
  [1305] Regular expressions made easy - building from components - (2007-08-16)
  [1251] Substitute operator / modifiers in Perl - (2007-06-28)
  [1230] Commenting a Perl Regular Expression - (2007-06-12)
  [1222] Perl, the substitute operator s - (2007-06-08)
  [943] Matching within multiline strings, and ignoring case in regular expressions - (2006-11-25)
  [737] Coloured text in a terminal from Perl - (2006-05-29)
  [608] Don't expose your regular expressions - (2006-02-15)
  [597] Storing a regular expression in a perl variable - (2006-02-09)
  [586] Perl Regular Expressions - finding the position and length of the match - (2006-02-02)
  [583] Remember to process blank lines - (2006-01-31)
  [453] Commenting Perl regular expressions - (2005-09-30)


Back to
Hotel door furniture
Previous and next
or
Horse's mouth home
Forward to
Presenting Melksham - for a weekend away in Wiltshire
Some other Articles
A tale of a wee wall
Before and After - Well House Manor
-> , >= and => in Perl
Presenting Melksham - for a weekend away in Wiltshire
C++ and Perl - why did they do it THAT way?
Hotel door furniture
Training rooms to learn Open Source programming
C++ - just beyond the basics. More you can do
The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl
Why shouldn't I spam?
4318 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/928_C-an ... -way-.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat