• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

Some new programming languages

lpetrich

Contributor
Joined
Jul 27, 2000
Messages
25,444
Location
Eugene, OR
Gender
Male
Basic Beliefs
Atheist
Here are some new programming languages that were created over the last decade.

Rust was created by the Mozilla team, as an alternative to C/C++ that is designed to have similar high performance while having much greater safety. Like most high-level languages, Rust does array accesses with a bounds-checked array object, rather than with pointer offsets as in C/C++. Rust goes a further, with explicit control of an object's mutability, so as to prevent unwanted changes. One defines an object with "let", and it may be the result of something done in run time. But after that, it is fixed. C++ "const" is similar, but it works in compile time and not run time. To make it possible to change that object, one needs to do "let mut". When passing an object as an arg, one has to make it "mut" to allow the function to change it. The Rust compiler also enforces a rule that there may be only one reference to each object that will allow making changes to it, though there can be several that will not allow such changes. This helps suppress multiple-change bugs.

However, Rust makes declarations easier with type inference, inferring a variable's type from how it is defined. One can override a type inference if one wishes, like giving a floating-point number an integer initial value.

Rust also does safe nullable or optional variables. A nullable variable is one that can be set to "no data". This is familiar from C/C++ and Java as null pointers, and Python as the "None" variable value. But none of them are completely safe, because attempting to work with the contents of a null variable will cause an exception condition. In plain C, it will cause a crash, in C++, it will do also, because it does not support catching that kind of exception, and in Java and Python, one can catch that kind of exception. But in Rust, when one wants to work with the contents of a nullable variable, one must check to see if it has data, and give what to do if it is null.

Rust also has type traits, a facility similar to Java interfaces or Objective-C protocols. In all three, one can define a set of methods that an object must implement. But Rust type traits allow for default implementations, like (say) is_unequal() in terms of is_equal().



Swift was created by Apple as an alternative to Objective-C, to get rid of the annoying C-ness in it. It has ideas in it "from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list". Ideas like nullable variables, type inference, protocols, and "categories", methnds that can be added to object classes at runtime.

Apple has implemented Swift interfaces for its Cocoa and Cocoa Touch standard libraries.


Kotlin was created as an alternative to Java, but one that can work with the Java standard libraries and runtime. Kotlin allows top-level functions rather than making every function an object method, what Java does. However, Kotlin has a behind-the-scenes container class for such functions so that they will be visible to Java code. Kotlin also makes every non-abstract object class final by default, meaning that such a class cannot be inherited from unless one defines it with "open". Like Rust, Kotlin makes every variable immutable or mutable.

Google now supports Kotlin for Android development.


From Google itself has come the Go programming language. Something like C, but careful about pointer safety. It has what its three main developers could agree on, meaning that it omits generics (C++ templates, Java, Kotlin, Rust, Swift), and inheritance of implementations.


There is a JavaScript front end called TypeScript that adds variable types. This is so that type errors will be caught in compile time, like in C/C++, Java, Rust, Swift, Kotlin, and Go. I'm reminded of this from David Gerrold's "The World of Star Trek":
... Gene L. Coon, line producer for STAR TREK, and the only man other than Roddenberry who could make the show work on a regular basis, has said, “All of your production problems can be solved best in the typewriter. They can be solved a lot cheaper and faster than they can on the set.”
Languages like Python catch type errors at run time, meaning that one can develop with them faster, and that they look less cluttered.


C++ itself has had continued development. The C++11 release of it has introduced some nice features: type inference with "auto", reading off other variables' types with "decltype", a foreach construction with syntax much like Java's:

for(type variable: list) {...}

anonymous functions or lambdas that can be inlined, "constexpr" for functions, meaning that they can be calculated at compile time if possible, initializer lists for container classes much like for plain-C arrays, and hashed associative arrays and unique-member arrays: "unordered_map" and "unordered_set" in addition to "map" and "set", which need ordering and which build data trees.

Hash best case: O(1), Tree best case: O(log(n)) for n items in a balanced tree
 
One of the points of a C++ object was making code and data private, invisible outside the object. You can not set a pointer to any private data or code in an object. I'd have to fact check, I believe a private pointer inside an object can not index ourtside the object.
 
I've never heard of such a thing. Pointers have the problem that they can be directed to anywhere in their code's memory space. Yes, *anywhere*. That ability can be used to break into some software with buffer overflows and the like.

Most high-level languages don't allow pointer arithmetic, and they are thus invulnerable to that sort of attack. C and C++ are exceptions, though widely-used ones.
 
One of the points of a C++ object was making code and data private, invisible outside the object.
I thought about it some more, and that is correct about when one is writing code. One can specify which level of access is permissible in a definition of an object, and the compiler will object if one attempts to access something made inaccessible. Private: visible only to object methods. Protected: visible only to object methods, and subclassed-object ones. Public: visible to all.
 
I used C++ in the 90s. I din't use all the functions oriented to large scale projects like inheritance. I used it to deal with large sets of calibration data and measurement data.

Under DOS before Windows and memory protection software could clobber the OS and software. Errant pointers often a cause. More than once using C I had to reformat the HD and reload the OS.

OOP is intended to minimize side effects by combing code and data operated on by ode in an object which can not corrupted by other objects.

It is also designed to support large scale multiple programmer projects. Write an object with a well defined interface, test it, and put it into a library for anyone to use. In c you did that with functions, but without protection.

It is also about code reusability.
 
Yes, a lot of C++ features are intended as convenience features for building software libraries. That's something necessary for large software projects.

C++ is also designed to banish the C preprocessor, though some of it remains without "proper" C++ replacement, like conditional compilation and inclusion of file contents. But C++ makes a lot of its uses unnecessary.

const: short for "constant". Declare something fixed, and the compiler will treat as an error any attempt to change its contents.
#define SIX (6)
const int SIX = 6;

inline: inline a function's code if it is not too large.

template: C++ generics.
#define MAX(x,y) ( (x) >= (y) ? (x) : (y) )
template<class T> T &MAX(const T &x, const T &y) {return (x >= y ? x : y);}
The & means reference, a sort of hidden pointer for avoiding making copies.
The const added onto it means that it won't be altered despite being called by reference.

Naive version:
template<class T> T MAX(T x, T y) {return (x >= y ? x : y);}
OK for lightweight objects, but for heavyweight ones, it makes copies.
 
Late binding vs early binding.

When you start a C++ program, or C, you can pass parameters to code. In C++ you can spawn objects at runtime.

C++ is more of a way of looking at software. It is a form of reductionism. Build objects with tested interfaces then build build the high level function from objects.

It is like designing an engine, transmission, and drive train for a car by three groups working to specs on how they interface..First define the app, then break down into subsections with interfaces.

Before OOP there was structured programming. Generally top down structure and execution. A mix of main program code and functions.

OOP is not necessarily top down sequential.

Structured programming

f1()
f2()
f3()

main(){

while(forever){

code
f1()
code
f(2)
code
f3()}
}

For OOP imagine a 3d network of C++ objects interacting not necessarily in any sequential order.

The standard C functions like strcpy() are library functions. The precompiled libraries are added to the compiled programs depending on what you specify.

You can compile custom math functions to a library and you can use them in your code just like standard C functions without having to always add the text code to your programs.

It is not so much an issue anymore, that reduces the time it takes to compile a program. On the old VAX system it could take an hour or more to compile.
 
Back
Top Bottom