Live data from Hacker News

Ada: a C Developer's Perspective

methodsandtools.com

71–80 of 157 posts

Re: Ada: a C Developer's Perspective

#71

Earlier quoted context omitted.

I think a lot of people would disagree with #1. There was a discussion on /r/technology yesterday where people were discussing how it was exactly the other way round – Ada has weird syntax (so many English words!) which slows adoption, and Rust is C-like enough that the target market of C/C++ users can pick it up, syntactically at least. I'm saying this having done a distributed systems course in Ada. It felt like wr…

> Structs/enums are also basically Scala. How so? Scala class bodies are a mix of ordered constructor statements and unordered declarations/method definitions, while Rust structs can only declare fields (without any sort of initial value). Scala enumerations (both scala.Enumeration and the more common sealed class versions) look nothing like a Rust enum; if anything Rust enums look like ML/Haskell algebraic type defi…

Ah, I see it's been a while since I've used Scala. I think I should have referred to case classes. Weak point nonetheless.

I did fail to mention the other very Scala thing: match expressions. Most complicated Rust match expressions could almost compile without errors in Scala.

Re: Ada: a C Developer's Perspective

#72
post #8
post #4

So how does Ada go speed wise (real world not micro benchmarks)? Were/are there legitimate reasons to opt for c over Ada?

On early PCs, Pascal and C were pretty much tied in popularity. Both were free to implement, and small enough that you could make a fast compiler on a typical PC with only 256-640 kB RAM. C won because it was more flexible and was chosen by Microsoft, but Pascal definitely had a strong following (it was the original Mac's API language, and on PC it was a major contender thanks to the nice and fast Turbo Pascal IDE).…

Was anyone building things like operating systems or drivers in pascal? AFAIK that was always the realm of c. Turbo pascal was the first language I was taught, I have a soft spot for it but I think it had largely faded away by then.

Re: Ada: a C Developer's Perspective

#73
post #72
post #8

Earlier quoted context omitted.

On early PCs, Pascal and C were pretty much tied in popularity. Both were free to implement, and small enough that you could make a fast compiler on a typical PC with only 256-640 kB RAM. C won because it was more flexible and was chosen by Microsoft, but Pascal definitely had a strong following (it was the original Mac's API language, and on PC it was a major contender thanks to the nice and fast Turbo Pascal IDE).…

Was anyone building things like operating systems or drivers in pascal? AFAIK that was always the realm of c. Turbo pascal was the first language I was taught, I have a soft spot for it but I think it had largely faded away by then.

http://wiki.osdev.org/Pascal#Past_uses_in_OS_development

I have vague memories of trying to write MacOS apps in CodeWarrior and needing to mark C functions as having a Pascal ABI...

Re: Ada: a C Developer's Perspective

#74
post #35

Here is my list of shortcomings when it comes to Ada 1) Ada is not a magic bullet, the seminal case study of why computer bugs are bad taught in CS courses around the world is the failed 1996 Ariane 5 rocket launch where the rocket veered off course and then exploded due to a software error that caused it not to understand the data it was getting from a sensor. More recently there are plenty of demonstrations of poor…

I feel like I have to rule out some misconceptions and defend Ada a bit, even though I don't use it very often any longer. Ada is not a magic bullet 1) Nothing is a magic bullet. (And certainly no actual user of Ada has ever claimed that it is a magic bullet.) Ada is not easy to write, it's around the level of C I grant you. 2) Ada is way harder to write than C, unless you're very proficient with it, of course. It's…

In regards to level of ease of writing, I'm assuming some level of competency in the languages we are talking about, all languages have a learning curve.

In regards to speed as other comments have also pointed out some of the asserts were optimised out of some of the Ariane 5 code, while the ones left in worked towards the cause of the issue ;)

The reason Java is in there is due to the libraries available, you can use those libraries with other JVM hosted languages like clojure ;) now tell me it's not maintainable. Similar reasons why python is in that list, I believe no OOP language is truly maintainable at this point, it adds to much complexity.

Re: Ada: a C Developer's Perspective

#75
post #4

So how does Ada go speed wise (real world not micro benchmarks)? Were/are there legitimate reasons to opt for c over Ada?

In theory, it's just as fast as C/C++, when you compare GNAT against GCC/G++. In practice, some language constructs are not as optimized as their C++ counterpart. The end result is that you can expect the Ada 83 subset to be extremely fast, but more recent constructs like OO and controlled types (equivalent to C++ virtual destructors) to be slower. All in all it has a pretty good performance story !

> In theory, it's just as fast as C/C++, when you compare GNAT against GCC/G++.

Is this the same theory that makes java is just as fast? Ie, if I wrote idiomatic Ada would the levels of indirection (pointers to pointers to pointers and virtual functions everywhere) by more like c or more like java?

Re: Ada: a C Developer's Perspective

#76
post #50
post #29

Earlier quoted context omitted.

> The subtyping feature I love the most. I only have very little experience with Ada, but being able to define a type whose values are integers in the range, say, 1 .. 7, to represent days of a week was an eye opener.

Range types are probably the main thing I miss from the Rust type system. But even without range constraints, wrapper types (called newtypes in Haskell and Rust) are great. Let's say you have a function that accepts a temperature. A temperature is a float, but you want to prevent the user from mixing up celsius and fahrenheit. This is what newtype looks like in Rust: struct Celsius(pub f64); struct Fahrenheit(pub f64…

This is exactly what C does.

  #include 

  typedef struct { double v; } Celsius;
  typedef struct { double v; } Fahrenheit;

  void
  print_celsius(Celsius temperature) {
      printf("Temperature is %f", temperature.v);
  }

  void
  compile_error(Fahrenheit temperature)
  {
      print_celsius(temperature);
  }
I suspect LLVM will clean this up to plain floats as well.

Re: Ada: a C Developer's Perspective

#77
post #70
post #37

Earlier quoted context omitted.

If you start a project today that depends on a library that was last updated in 2002, then may God help you.

Well, why? Why would a library be bad just because it hasn't been updated in 15 years? Does it spoil? Maybe it doesn't need to be updated.

Environment rot, yes (protocol changes, bug that weren't found yet by the time that library come out, etc...).

Re: Ada: a C Developer's Perspective

#78
post #75

Earlier quoted context omitted.

In theory, it's just as fast as C/C++, when you compare GNAT against GCC/G++. In practice, some language constructs are not as optimized as their C++ counterpart. The end result is that you can expect the Ada 83 subset to be extremely fast, but more recent constructs like OO and controlled types (equivalent to C++ virtual destructors) to be slower. All in all it has a pretty good performance story !

> In theory, it's just as fast as C/C++, when you compare GNAT against GCC/G++. Is this the same theory that makes java is just as fast? Ie, if I wrote idiomatic Ada would the levels of indirection (pointers to pointers to pointers and virtual functions everywhere) by more like c or more like java?

Well, yes and no :) Ada is very close to C++ in terms of runtime abstraction, unlike Java, so it's not relying so much on the "sufficiently smart compiler" fallacy.

Also, there are several idiomatic dialects of Ada, because Ada has a facility to deactivate language features at compile time. Some people in safety critical don't want any dispatch for example.

FWIW I ported a quite large code base from C++ to Ada so I'm have first hand experience with this.

Re: Ada: a C Developer's Perspective

#79
post #50

Earlier quoted context omitted.

Range types are probably the main thing I miss from the Rust type system. But even without range constraints, wrapper types (called newtypes in Haskell and Rust) are great. Let's say you have a function that accepts a temperature. A temperature is a float, but you want to prevent the user from mixing up celsius and fahrenheit. This is what newtype looks like in Rust: struct Celsius(pub f64); struct Fahrenheit(pub f64…

This is exactly what C does. #include typedef struct { double v; } Celsius; typedef struct { double v; } Fahrenheit; void print_celsius(Celsius temperature) { printf("Temperature is %f", temperature.v); } void compile_error(Fahrenheit temperature) { print_celsius(temperature); } I suspect LLVM will clean this up to plain floats as well.

Whether any compiler "cleans this up" depends in the system's ABI; parameter calling conventions are not up to the compiler to decide (unless it can prove that a given function cannot be called from code it does not control).

That said, yes, modern ABIs for modern machines usually pass single-element structures of primitive types in registers of the appropriate type. x86 (32-bit) is not modern in this sense: depending on the exact ABI used, these structures might well be passed on the stack or in an integer register.

Re: Ada: a C Developer's Perspective

#80
post #50

Earlier quoted context omitted.

Range types are probably the main thing I miss from the Rust type system. But even without range constraints, wrapper types (called newtypes in Haskell and Rust) are great. Let's say you have a function that accepts a temperature. A temperature is a float, but you want to prevent the user from mixing up celsius and fahrenheit. This is what newtype looks like in Rust: struct Celsius(pub f64); struct Fahrenheit(pub f64…

This is exactly what C does. #include typedef struct { double v; } Celsius; typedef struct { double v; } Fahrenheit; void print_celsius(Celsius temperature) { printf("Temperature is %f", temperature.v); } void compile_error(Fahrenheit temperature) { print_celsius(temperature); } I suspect LLVM will clean this up to plain floats as well.

[deleted]
Post reply on HN