Author Topic: Programming languages  (Read 6753 times)

Offline cjameshuff

  • Mars
  • ***
  • Posts: 373
Programming languages
« on: October 01, 2014, 07:17:30 PM »
C++ is incredibly baroque.  Try Python instead.

While I can't deny that it's a rather terrible and overly complex language, C++11 and C++14 are much improved (practically a new language, really), it can achieve good performance, and it interoperates well with C. If you want baroque, look at Perl. As for Python...I find the syntax to be quite awful, beginning but not ending with the indentation significance and lack of visible delimiters for code.

I generally use C on embedded hardware, C++ for most things on the desktop, and Ruby for various scripting tasks and programming stuff that doesn't need high performance. I've also been looking at Julia (http://julialang.org/), which looks like a nice high-performance, high-level language...my main complaint is the rather misguided decision to use 1-based indices for arrays. While that fits better with what novices expect from common usage in everyday life, in the world of algorithms, it makes many things much more clumsy and cluttered.

Offline ka9q

  • Neptune
  • ****
  • Posts: 3014
Re: Programming languages
« Reply #1 on: October 01, 2014, 09:50:28 PM »
I tend to be pretty conservative about new programming languages. I've been around long enough to have heard it many times: this new language will solve all our problems!

I've been writing C code since about 1977, and it's still my primary language. Before that I did BASIC, FORTRAN and PL/I but have had little need to use those in a long time.

I learned C++ because it was heavily used at work, but every time I try to use it for my own programming I find that its features are too expensive in terms of performance. The overhead of constructor/destructor calls is intolerable for small, heavily used object types. So I go back to C.

I learned Perl to use it for what it was originally designed to do: perform quick extractions from textual log files using rules too complex for grep or awk. I liked that it had strings and regular expressions built directly into the language, but it has far too many warts and syntactical irregularities to be really useful for serious programming. Yet that's how many people use it, which is distressing. Our Logitech (Squeezebox) players use a server written in Perl, and it's been down for over a month because of a library version conflict that I haven't bothered to dig into. This kind of stuff happens all the time with that language.

People tell me I should learn Python, but last I looked it didn't have the built-in support for regular expressions. Has this changed?

Offline JayUtah

  • Neptune
  • ****
  • Posts: 3789
    • Clavius
Re: Programming languages
« Reply #2 on: October 01, 2014, 11:50:49 PM »
If you want baroque, look at Perl.

I have, and I want to claw my eyes out.  That is hands-down the most stupidly designed programming language ever invented.  I have had to deal with many Perl code bases, all of it atrociously unmaintainable.  And all of it apparently written according to what seems to be the Perl programming community's belief that if code seems incomprehensible then you just don't know enough Perl.  If I can get the customer's permission, I'll post some for you to eviscerate.  I'm convinced that no one should ever use Perl for commercial software development.

Quote
As for Python...I find the syntax to be quite awful, beginning but not ending with the indentation significance and lack of visible delimiters for code.

I originally considered those to be weaknesses too before I started programming using it, and I think to some extent they are.  But keep in mind that I started with assembler and Fortran, so horizontal spacing is something I've always associated with syntax.  So they really don't bother me that much.  In practice we use both horizontal spacing and delimiter characters e.g., { } in all our code, so Python's designers seem to have just bit the bullet and used that to group instructions.

Quote
I generally use C on embedded hardware, C++ for most things on the desktop, and Ruby for various scripting tasks and programming stuff that doesn't need high performance.

Tomorrow I need to learn Ruby.  Any good references?  For high-performance new stuff I use C/C++, but I still have to deal with legacy Fortran code bases.  Sadly I don't see much need for compiled languages on the desktop.  If I'm paying for the development I'd rather just buy eight more cores and 32 gigabytes more memory with the money I'd have spent on programmer time to debug the memory mishandling.  Don't get me wrong, I understand very well how to debug compiled code memory leaks.  But it seems that's a dying art, and only the very highest performance code needs to do its own memory management these days.

Try HAL/S sometime, especially the algebraic notation.  It's trippy.

Quote
...rather misguided decision to use 1-based indices for arrays.

* JayUtah facepalms.

At the same time, I think it's pretentious of some computer science authors to start their texts at Chapter 0.
"Facts are stubborn things." --John Adams

Offline JayUtah

  • Neptune
  • ****
  • Posts: 3789
    • Clavius
Re: Programming languages
« Reply #3 on: October 02, 2014, 12:03:15 AM »
I learned C++ because it was heavily used at work, but every time I try to use it for my own programming I find that its features are too expensive in terms of performance. The overhead of constructor/destructor calls is intolerable for small, heavily used object types. So I go back to C.

Indeed, the STL makes C++ usable as a high-level language, better than most for data and process modeling.  But the resulting code is still heavyweight.  It doesn't work very well for engineering support, but then again what I'm talking about is adaptively tuned performance on terascale supercomputers.  C is barely fast enough for some of that.

If you can find the original Mozilla code release, which is based on the Netscape 3.x and 4.x commercial code bases, you can see some very elegantly written object-oriented code in plain C.

Quote
People tell me I should learn Python, but last I looked it didn't have the built-in support for regular expressions. Has this changed?

Yes, but it will never incorporate them the same way Perl does.  You still have to do

Code: [Select]
import re

if re.match( pattern, string ):
    do_stuff()

which makes it clumsy to simply match a quick-and-dirty regex, but the module/function approach is the Python philosophy for almost everything.  It's both a strength and weakness of the language, IMHO.
"Facts are stubborn things." --John Adams

Offline cjameshuff

  • Mars
  • ***
  • Posts: 373
Re: Programming languages
« Reply #4 on: October 02, 2014, 02:51:17 PM »
Quote
I generally use C on embedded hardware, C++ for most things on the desktop, and Ruby for various scripting tasks and programming stuff that doesn't need high performance.

Tomorrow I need to learn Ruby.  Any good references? 

Well, don't confuse Ruby and Rails. The latter, IMO, makes use of the malleable nature of Ruby's syntax and ability to hook into the runtime to an abusive degree, and bits of its core philosophy such as "convention over configuration" profoundly frustrate me. A lot of Rails stuff is undocumented, with the assumption that writers of new code can just follow the conventions they picked up by pair programming with an expert, and their overriding of method_missing to automatically generate new method names for everything means that very little code is needed, but it also means that it can be near impossible to work out what an unfamiliar piece of code actually does.

The official documentation for Ruby is pretty decent for the most part, though lacking in detail in areas:
http://www.ruby-doc.org/core-2.1.3/
http://www.ruby-doc.org/stdlib-2.1.3/

And Pry is a quite good replacement for the standard Ruby REPL:
http://pryrepl.org/

And though I complained about Rails abusing method_missing, the ability to do stuff like that does make Ruby very useful for writing DSLs:
https://github.com/cjameshuff/usbtools/blob/master/examples/lpcusbdesc.rb


For high-performance new stuff I use C/C++, but I still have to deal with legacy Fortran code bases.  Sadly I don't see much need for compiled languages on the desktop.  If I'm paying for the development I'd rather just buy eight more cores and 32 gigabytes more memory with the money I'd have spent on programmer time to debug the memory mishandling.  Don't get me wrong, I understand very well how to debug compiled code memory leaks.  But it seems that's a dying art, and only the very highest performance code needs to do its own memory management these days.

I've actually been considering learning a newer version of Fortran. It has some attractive features in terms of control of how calculations are performed and scaling across multiprocessor systems, and seems to have shed much of the ugly baggage from early Fortran.

Ada 2012 interests me as well, for rather different applications:
http://www.embeddedrelated.com/showarticle/585.php


Try HAL/S sometime, especially the algebraic notation.  It's trippy.

...ASCII-art superscripts/subscripts?


Quote
...rather misguided decision to use 1-based indices for arrays.

* JayUtah facepalms.

It's apparently pretty much because that's how MATLAB does it, and what the common convention in math is.

Offline JayUtah

  • Neptune
  • ****
  • Posts: 3789
    • Clavius
Re: Programming languages
« Reply #5 on: October 02, 2014, 03:40:47 PM »
Well, don't confuse Ruby and Rails.

Not a problem.  My interest is connected mostly to Chef, and I'm researching how commercially sustainable Chef cookbooks are for a certain task.

Yes, I quickly found www.ruby-doc.org and that should work nicely, thanks.

Quote
I've actually been considering learning a newer version of Fortran. It has some attractive features in terms of control of how calculations are performed and scaling across multiprocessor systems, and seems to have shed much of the ugly baggage from early Fortran.

It has.  There is money in optimizing compilers for modern Fortran, and I've seen NASA's most recent fluid-dynamics code for terascale multiprocessors.  Fortran may have long roots, but the flower it bears today smells rather sweet.

Quote
...ASCII-art superscripts/subscripts?

Among other things, but yes.

I have snippets of code laying around all over the place to do various control tasks, many of which are just boilerplate on top of linear algebra principles.  Having matrices and vectors as a first-class data structure is quite handy, if only the language had an implementation beyond a small class of spacecraft and ground computers.  I've located a group that's working to put HAL/S on the x86 architecture.  That should be quite interesting.

Quote
It's apparently pretty much because that's how MATLAB does it, and what the common convention in math is.

I guess the maxim to respect thy problem domain applies here.
"Facts are stubborn things." --John Adams

Offline Luke Pemberton

  • Uranus
  • ****
  • Posts: 1823
  • Chaos in his tin foil hat
Re: Programming languages
« Reply #6 on: October 04, 2014, 06:58:08 PM »
I spent some time working with Delphi Pascal.  It was one of the most bitter experiences of my life.  :'( 
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former - Albert Einstein.

I can calculate the motion of heavenly bodies, but not the madness of people – Sir Isaac Newton.

A polar orbit would also bypass the SAA - Tim Finch

Offline Trebor

  • Earth
  • ***
  • Posts: 214
Re: Programming languages
« Reply #7 on: October 13, 2014, 03:20:28 PM »
I spent some time working with Delphi Pascal.  It was one of the most bitter experiences of my life.  :'( 

I actually quite liked it :)
Spent years working with the thing professionally till it died a slow and painful death.

But if you wish to rekindle the pain there is an open source clone of it available....

Offline gwiz

  • Mars
  • ***
  • Posts: 335
Re: Programming languages
« Reply #8 on: October 14, 2014, 05:54:24 AM »
But if you wish to rekindle the pain there is an open source clone of it available....
Really?  Details, please.  I wrote a few PC programs with it, but can't do any modifications to them for the current versions of Windows.
Multiple exclamation marks are a sure sign of a diseased mind - Terry Pratchett
...the ascent module ... took off like a rocket - Moon Man

Offline Trebor

  • Earth
  • ***
  • Posts: 214
Re: Programming languages
« Reply #9 on: October 16, 2014, 03:16:10 PM »
But if you wish to rekindle the pain there is an open source clone of it available....
Really?  Details, please.  I wrote a few PC programs with it, but can't do any modifications to them for the current versions of Windows.

It's here :
http://www.lazarus.freepascal.org/
It is actually just about usable. With a bit of work Delphi code will compile quite well in it.

Offline gwiz

  • Mars
  • ***
  • Posts: 335
Re: Programming languages
« Reply #10 on: October 17, 2014, 08:53:33 AM »
It's here :
http://www.lazarus.freepascal.org/
It is actually just about usable. With a bit of work Delphi code will compile quite well in it.
Thanks for that.
Multiple exclamation marks are a sure sign of a diseased mind - Terry Pratchett
...the ascent module ... took off like a rocket - Moon Man