Friday, May 26, 2023

Programming Languages: the more the merrier

What your favourite language? All of them!

This post has some random notes on random programming languages. I'm just keeping some links from when I have used the various languages for different products and projects.

I find programming languages fascinating; you can instruct the computer to... compute things.


Programming language design is fundamentally mathematical. It follows rules defined in set theory and logic (predictive and propositional)

Every powerful language has
  1. PRIMITIVES (the simplest entities)
  2. MEANS OF COMBINATION (to create complex entities)
  3. MEANS OF ABSTRACTION (treat complex entities as if they were primitives) 

Languages and Environments

Does it matter what language used? The only thing that can be guaranteed is that, one day, there will be a better way to tackle a problem. Any problem. The language is a tool to create a solution for a particular problem, at a particular time. It is the best solution at the time, but there will be a better on around soon, so don't get too attached to it.
There is no "real man's" language either. Some are more difficult to do well, but there can't be any impression that one is a magical language that does everything well. As a consequence of the environment people can find themselves in, they could become fans of a particular language, but they should tread carefully and pay attention, or else they will miss the next change.
 
It does say something about a programmer when they are willing to learn a new language without having required to from work or school. Programming languages are tools in a toolbox. The more the better. If you only have a hammer in your toolbox, then the only problems you can solve are the ones involving nails.
 
If programming languages were cars? www.cs.caltech.edu/~mvanier/hacking/rants/cars.html
Should programmers be language-independent? blog.reindel.com/2007/08/28/should-programmers-be-language-independent lang: http://www.cs.rice.edu/~taha/teaching/05S/411/ lang: http://www.newartisans.com/2009/03/hello-haskell-goodbye-lisp.html A timeline of programming languages: http://www.levenez.com/lang/history.html
Which are faster? http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all

Most programmers start programming by using a Procedural language. These are bits of logic, and when one piece gets too big it is split up into various functions to make the whole thing more readable.
C, Pascal, Shell scripting, BASIC, web page functions: these are examples of procedural languages.
A good course to take when learning programming is Comparative Languages (or some other similar title). This sort of course requires that a working useful program be constructed with each one of the various styles of programming. A language is picked to demonstrate the use of Iterative, Object oriented, Functional, Prototypical and another that mixes styles. This is helpful to distinguish the styles in a different syntax and semantics.
 
Essential to this is the understanding of 'static' and 'dynamic' typing (Early binding and Late binding of values). When comparing the two approaches, a deeper understanding of Compilers and Interpreters is gained in the process.

Static or Dynamic typing

It's really a system of typed 'things' that you are dealing with: http://en.wikipedia.org/wiki/Type_system
http://okmij.org/ftp/Computation/type-arithmetics.html
 
Types are associated in early or late binding Languages will have basic built in types like numbers and characters.
 
For statically typed languages the programmer is concerned with flow, understanding the machine, thinking assembly, when programming. It is on the onus of the programmer to create the code that can run fast on a particular processor. This is a skill that's hard to find.

For dynamically typed languages the programmer allows the computer to profile and optimize the code.
Then isn't dynamic typing better? Well, it can be, but due to the run-time nature of the type checking, there is a danger of the problems only creeping up during run-time. These problems would have otherwise been caught at compile time.
This risk can be alleviated with extensive unit testing.
 
Also, to make the system more 'dynamic' most statically typed languages allow type casting which occurs at run-time anyway. You'll get the same problem.
Interfaces and the separation of the implementation concerns from them is a cornerstone of industrial OO development. Dynamic languages are difficult use in a large team/ shared codebase because of their lack of the interface.
 
This may only be a matter of communication and documentation. A poorly written statically-typed interface will be a problem no matter what.
So, it is safer to use a statically typed language, but all the features that have been added to make these type systems more dynamic spoils this by the resulting runtime type checking. There has to be room for both: static interfaces that are safe to use and dynamic typing when needed.
The inevitability of dynamic languages? www.dotnetrocks.com/default.aspx?showNum=277

Dynamic Typing

Lisp/Scheme

to add one and two:
(+ 1 2)

Lisp, at first, may seem like more of a collection of syntax than a language. It's really a great language and environment when you get into it. You can also learn some great strategies that carry over to other environments. It has pedantic regularity (with everything being an s-expression)

It's pretty amazing that a language invented in the early 50's has continued to grow more productive and popular. It is still lacking in many of the tools for the style of web applications that are needed today, but that's only a matter of time. Though time may be not on lisps side when considering the momentum behind Python and Ruby. Again, it is still around, so we'll see.
http://www.paulgraham.com
http://www.norvig.com/
Scheme is a subset of Lisp, with the intention to be correct and a good base for teaching.

An Introduction to Computer Science Using Scheme: http://www.gustavus.edu/+max/concrete-abstractions.html

StandardML
OCaml: http://www.ocaml-tutorial.org/ http://caml.inria.fr/
F# http://research.microsoft.com/fsharp/fsharp.aspx http://blogs.msdn.com/chrsmith/archive/2007/11/10/Project-Euler-in-F_2300_-_2D00_-Problem-5.aspx
http://en.wikipedia.org/wiki/Haskell_(programming_language) http://cgi.cse.unsw.edu.au/~dons/blog/2006/12/16#programming-haskell-intro
XSL is a language for transforming and formatting XML graphs.

Static typing and Curly braces

C, C++, Java, D and others are all Algol derived languages

D

Walter Bright has done a huge amount of significant work over the years; writing a compiler is a serious piece of work. http://www.walterbright.com/

http://boscoh.com/programming/some-reflection-on-programming-in-d-and-why-it-kicks-serious-ass-over-c-leaving-it-died-and-tired-on-the-sidewalk#cpreview
http://www.dsource.org/

C++

C++ is a programming language that is the most mature production quality language in use today. It's my bread and butter.
 
From a c++ implementation view, understanding how a nice memory managed smart pointer works will help with issues in the various components tying together. If things get leaky, it gets bad in a hurry. You could have an engine like Ogre, with some other components from the operating system (rendering libs like Directx and opengl), and then ties to other stuff; so using Boost and STL will help. Once everything seems great, get a good profiling tool.
 
STL - this is a such a standard library that is has to be considered as part of the language itself. Use of the algorithm approach on generic containers solves many problems. STL collections, iterators STLPort - http://www.cprogramming.com/tutorial/stl/stlmap.html The C++ Standard Template Library (STL), a generic programming paradigm that has been adapted to the C++ programming language, and is an extensible framework for generic and interoperable components.
 
c++ http://nuwen.net/14882.html 
BOOST - you will need a good reference counting smart pointer. The shared_ptr and auto_ptr will come to your rescue. Use boost unit tester
 
http://www.boostcookbook.com/Recipe:/1235053 http://www.boost.org/libs/test/doc/components/utf/index.html http://sourcemaking.com/refactoring/split-temporary-variable C/C++, C# cheat sheets www.scottklarr.com/topic/121/c-cpp-c-cheat-sheets Linking C++ objects using references the-lazy-programmer.com/blog/?p=12
 
C++ make everything that can be a const a const, inline small setter/getters

Scott Meyers : Effective C++. Just read it and do what he says.

Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu

Herb Sutter
http://www.cppreference.com/

www.cprogramming.com/
www.cuj.com

C#

C# was created to bring C++ style to the Microsoft (ECMA standardized) Common Language Runtime. The language was created by Anders Hejlsberg, who made Turbo Pascal; my first programming environment.
It has great libraries and MS support, and many features to allow it to act like a functional structued language.
C# 3.0 tutoria www.programmersheaven.com/2/CSharp3-1

C++/CLI

C++/CLI is the implementation of standard C++ for the Microsoft Common Language Runtime. It's the 'managed' version of C++, so it's has support for memory management that is lacking in traditional 'unmanaged' C++.
Here is a good intro: http://www.codeproject.com/managedcpp/cppcliintro01.asp

Java


Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.

Java was created with many features to try to make high-level programming easier. It's a safer, more mellow, C++. While C++ has direct access to the hardware, Java is interpreted in a virtual machine.
It's really taking its place as the 'enterprise' language, sort of the current standard for most programming. This is reflected through it's use as the most common teaching language in north american universities. As long as the programs don't just teach one language this is fine. However long Java lasts in this place, it has brought many people to programming that would have stayed away otherwise.

When Java came out in 1995 it came with a lot of hype about this safer style of handling memory allocation and clean-up through the garbage collection process. It is an interpreted language, so instead of compiling it to a specific platform, the code is compiled into an intermediate bytecode language, which then is run on a Virtual Machine. The VM is written to specific platforms. This enables the bytecode to run, unchanged, on many different platform.

The extra step of the virtual machine running the bytecode made Java much slower than C++ at first, but since then the speed of the hardware and optimizations to the bytecode and the virtual machine have closed the gap considerably. Java is, 10 years on, an industrial-strength langauge now.

Java has a cool feature called Reflection, where you can analyse objects at run time. C# has this same feature.

I use the NetBeans IDE that Sun has since bought and is now presenting as an alternative to the Eclipse project. It's familiar, so its fine for me.
Spring framework uses inversion of control to enable regular objects to be used without a lot of extra required.

Scala

Scala is a functional, descriptive language that runs on the Java Virtual Machine. It has many features around concurrency.
http://www.scala-lang.org/
http://langexplr.blogspot.com/2007/07/structural-types-in-scala-260-rc1.html

Groovy

Groovy extends the JDK libraries and make a great tool for all the engineering tasks around the Java is too clunky to do. It's has great dynamic features.
//a program to convert a number into a text representation of its digits // 356 should say 'threefivesix' def num = '356' def words = ['zero','one','two','three','four','five','six','seven','eight','nine'] num.each(){println words.get(it.toInteger())}

Clojure

Clojure is a Lisp dialect http://clojure.org/rationale

Pascal

This language introduced me to the world of programming.

Mocha/Javascript/ecmascipt

Fascinating story about how this language came about.
Use a good library to abstract yourself from inconsistent implementations in browsers. 

this
use of the keyword 'this' can cause issues in annoymous functions. You can assign the value of 'this' to another private member, but you also use the built in methods of 'call' and 'apply' to preserve the scope of the contents of 'this'.

http://www.crockford.com/javascript/private.html http://jibbering.com/faq/faq_notes/closures.html Interesting views on the world's most misunderstood programming language and jslint from Douglas Crockford Javascript and JSON Javascriptkit for comprehensive language reference Excellent free 

JS in the browser is the heart of the browser platform. Its allows the script to manipulate any part of the document currently loaded. An easy example is to write out some text and have function that changes it:

Written in a short time by one person it has become the most used language in history. It's much maligned, and has some issues, but it's actually a wonder how it's worked as well as it's had, for so long.
To encourage some standardization the neutral ecma spec emerged.


No comments:

Post a Comment