10 ms·
Ada: a C Developer's Perspective
- aamederen 9y agoI had a strange internship topics involving Ada. I tried to run a huge program (a simple stdio wrapper around a huge library actually) on an Android machine (Android 2.3, ARM). At that time, the only ADA compiler for ARM was available on BSD so I had used a Windows machine for development and a OpenBSD laptop for compiling the wrapper. The subtyping feature I love the most. You see the benefit when you need to call a function which is taking many numeric arguments, all of them is a subtype so you can't give the arguments in the wrong order (latitude and longitude for example).
- gmac 9y agoFor this specific benefit, named parameters are arguably at least as useful, such as in Swift and Objective-C. [someObject doSomethingWithLatitude:55.0 longitude:0.0];
- krylon 9y ago> 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.
- dbrgn 9y agoRange 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); fn print_celsius(temperature: Celsius) { println!("Temperature is {}", temperature.0); } It will fail to compile if you accidentally pass a Fahrenheit value to `print_celsius`, but at compile time all values are optimized down to plain floats, without any runtime cost. More programming languages should adopt this concept :)
- krylon 9y agoHuh. That's clever. This approach should also work in other languages, say, C/C++/C#. I don't remember if C uses structural identity for struct types, but it might work.
- jononor 9y agoNo identity or equality concept in C for structs apart from their address, I'm afraid. In C++ one can define a comparison operator, but it has to be implemented manually. Not that you can use the language-provided == on floats anyway, due to precision issues you should always check if the difference is below a specified limit...
- krylon 9y ago> Not that you can use the language-provided == on floats anyway, due to precision issues you should always check if the difference is below a specified limit... Hehe, I've been there. ;-) Fortunately, that code dealt with physical coordinates, so if two points were less than 100µm apart, they were equal for our purposes.
- johncolanduoni 9y agoOne of my favorite features of Scala that Java is missing is Scala's newtype-like functionality. It lets you define types which get erased to another one the JVM level (so there's no unnecessary boxing) but are checked in Scala and can hide their interior type and provide different methods.
- wBI8j2bsb 9y agoThis is exactly what C does. #include <stdio.h> 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.
- 9y ago
- oblio 9y agoI find this regression kind of strange. Pascal had number ranges in the 80s! I don't get why no modern language adopted them...
- deleted 9y ago[deleted]
- kqr 9y agoThough if you're dealing in days of the week, you probably want an enumeration to avoid the whole "does 1 mean Sunday" thing.
- AstralStorm 9y agoWhich is why Ada has a Day type, an enumeration.
- kqr 9y agoImportant terminology nit: subtypes and derived types are two different things in Ada. A "subtype" is essentially a local new name for an existing type (it makes little sense to export subtypes). A derived type is a new type that is based on another type, but can be restricted to a subset of values of the original type, and cannot be interchanged with the original type.
- yoz-y 9y agoI am going to be that guy and say: Poorly compressed JPEG images for text examples?
- breeze_em_out 9y agoEvery time I see that shit I think, "Man, I'm glad we learned how stupid that is." but then immediately after I realize that people are still doing it all the time, because I think that same thought all the time. People are so STUPID! "Oh my god breeze, you are so rude, just because people programming critical infrastructure systems literally can't copy and paste things doesn't mean they're stupid!" -- Stupid people' Why yes. Yes, it actually does. That you don't like me saying it, doesn't make it any less true, and in fact gives me great pleasure in saying it.
- pjmlp 9y agoI get emails all the time where people use word or powerpoint documents with just one single image pasted inside, instead of attaching it to the email or sending it in HTML format.
- coldtea 9y agoOr much smarter than you, but wanted to show the examples with syntax highlighting but couldn't be bothered to get some editor that exports as HTML or some plugin (both of which might not even be allowed/quick to install on the CMS they use). As for the extra compression, they could just not care as the text is still visible enough, it's not supposed to be a textbook, and it's small and loads fast.
- flukus 9y agoSo how does Ada go speed wise (real world not micro benchmarks)? Were/are there legitimate reasons to opt for c over Ada?
- pavlov 9y agoOn 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). Ada was a complicated and rigid language designed by a Department of Defense committee. That was not great PR for those early individualist PC users. (Who wants to program in the language of "The Man"?) If Pascal was a Cessna and C was a Learjet, then Ada was the F-35 -- complex, expensive, late.
- breeze_em_out 9y agoAda is the F14. Expensive, works well, but ya really just don't need it most of the time.
- taneq 9y agoSo what's the F/A-18?
- rpeden 9y agoMaybe Java? It's everywhere, can fulfill just about any role you throw at it, but isn't really the world's absolute best tool for most of those roles.
- breeze_em_out 9y agoI almost said Javascript out of ubiquity, but it'd be a grave insult to the plane. Java is a good answer, maybe C#, maybe Python. The language needs to be one that gets a lot of work done, and is reliable. What's a language that's just always got your back in a situation? That's the F/A18.
- evacchi 9y agoIt's such a pity these days there is no modern tool chain/workflow for Ada (or C++ for that matter). I mean, a package manager, a build tool with integrated dependencies. As far as I know, there is very little open source software for Ada. It's a shame, because I feel like the language would become more mainstream, if only better tooling was easily available.
- pavlov 9y agoFor C++, I'm reasonably happy with CMake and the Jetbrains CLion IDE. CMake makes it relatively painless to wrap multi-platform dependencies without having to explicitly know whether they come from a Unix package manager or from Windows DLLs.
- evacchi 9y agoI wish there were a simplified (as in automated) and "community-blessed" workflow at least for static binaries with source dependencies, like all the popular "modern" PLs are doing these days. I'm saying this as a newcomer (in C++ land) that finds the lack of this kind of tooling a bit intimidating.
- pavlov 9y agoI know what you mean. It's just really hard to bolt dependency management on C family languages, and so many ways it can exacerbate the problem by adding another layer of accidental complexity... (IMHO, CocoaPods is a good example of how a community-managed library dependency manager can end up creating a worse mess than the one it tried to solve.) The Rust team started working on a package manager early as part of the language design, which seems like the only way to make it actually work.
- steveklabnik 9y agoFun bit of history: it's a hard problem! Rust went through three different package managers in its history: 1. Cargo. But not the one you've heard of. A small Python script that pulled stuff off of GitHub. 2. Rustpkg. Felt like Go's tooling. https://doc.rust-lang.org/0.9/guide-rustpkg.html https://doc.rust-lang.org/0.9/guide-rustpkg.html 3. Cargo, the one we still use today. https://mail.mozilla.org/pipermail/rust-dev/2014-March/009087.html https://mail.mozilla.org/pipermail/rust-dev/2014-March/00908... just over three years ago.
- sp0ck 9y agoIt's not only a language that is key to success. Libraries. I searched for LDAP support for ADA (old protocol used by many companies). I found library (http://savannah.nongnu.org/projects/adaldap/ http://savannah.nongnu.org/projects/adaldap/) with latest news from 2002 and CVS repo :) Then I search for SNMP (another dinosaur still in wildly use) - similar result. Second - many solutions/libraries are purely commercial. You need basic open protocols support by default /free. Otherwise such great language will still be at it's niche. Rust is on a good path to became XXI century successful Ada :)
- JohnStrange 9y agoAda is so stable and backwards compatible that old libraries will work just fine, unless they have external dependencies or depend on things that change fast in the outside world. For me personally Rust is not a good Ada replacement, because 1) it has the usual obscure syntax - maybe to attract C++ programmers, who seem to like obscurity -, 2.) many semantic tricks and borrower idiosyncrasies that makes it harder to write, read and maintain than idiomatic Ada, and 3) it's fast changing. The good thing about Ada is that it is self-documenting, it's almost impossible to intentionally or unintentionally obfuscate it, and once you've written a program it will continue to work 10-20 years later.
- deleted 9y ago[deleted]
- adrianN 9y agoIf you start a project today that depends on a library that was last updated in 2002, then may God help you.
- btrask 9y agoSame goes for a library that was last updated 5 minutes ago though.
- throwaway7645 9y ago
- samuell 9y agoAda ticks a fair amount of the boxes in the "Interesting statically compiled languages by wishlist features" google doc, which I started, and had some crowd-sourcing help to fill in: https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__nzbCSFnnHicWrjxpW5l6-O3w https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__n... (Would be cool if we could fill out those remaining white cells btw ;) )
- koja86 9y agoAda caught my attention recently. I am just curious - how is Ada job market? Any jobs other than military projects?
- tom_mellior 9y agoIt's also used in other embedded systems. Based on public talks, Thales (https://en.wikipedia.org/wiki/Thales_Group https://en.wikipedia.org/wiki/Thales_Group) seems to be using it a lot internally, and not everything they do is military. Here's a CubeSat operating system written in SPARK/Ada: http://www.cubesatlab.org/CubedOS.jsp http://www.cubesatlab.org/CubedOS.jsp
- reacweb 9y ago"Code should be easy to write, easy to read, easy to maintain, and most importantly, it should be reliable". Ada is not easy to write. Perl is easy to write (but not easy to read or maintain). When I was student, Ada was the main language at my school. It was used the first year to teach algorithms and the second year to teach parallelism. During the first year, I have also learned C by myself for curiosity. After the summer holidays between first and second year, I had forgotten most of the syntax needed to start a new program in Ada, but I was remembering perfectly well how to code in C. Even After 8 years of usage of Ada, I still needed the user manual regularly. After less than 1 year of usage of C, I could sell my R&K.
- reacweb 9y agoAs a disclaimer, I love Ada (and Perl) and I regularly despise C++.
- e12e 9y agoHow would you rate your young self on the "hello-my-name-is-scale", as I like of to think of Stroustrup's notes in his short article from 1999[1] -- in C and Ada at the time? Would your C code "blow up" differently from your Ada code, do you think? I'm not much of a fan of C++ myself, but I often find myself looking back at that short note, as a pretty valid criticism of how C tend to mix some parts that appear simple with some very complex actual behavior (eg: printing strings, reading in strings and integers). [1] http://www.stroustrup.com/new_learning.pdf http://www.stroustrup.com/new_learning.pdf "Learning Standard C++ as a New Language"
- the-dude 9y agoK&R, please.
- samuell 9y agoFor anyone interested in learning more, or helping collect the best Ada links, I started out on an "Awesome Ada" list some time ago: https://github.com/samuell/awesome-ada https://github.com/samuell/awesome-ada
- ewanm89 9y agoHere 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 security in commercial plane avionics systems. 2) Ada is not easy to write, it's around the level of C I grant you, but it is not easy by any means, more importantly it is complex not simple. Each of those "features" like assert adds a layer of complexity to the system making it far harder for the programmer to write for. I think we all agree if we could program with simple functions that each do one thing and one thing well then combine those functions makes for a much simpler language and easier to think about. 3) Overhead, each of these features like assert adds a lot of overhead into the system, this is just not viable in a lot of systems, whats more those features are optional, so it is the first thing to drop where possible. 4) Toolchain and library support, most of us can't afford expensive toolchains and libraries, we don't work for very rich government contractors. Also we need libraries and toolchains are well maintained. Java has a massive standard library and a lot of free 3rd party libraries available, C/C++, python, perl, ruby, rust, javascript, c#, clojure... are all similar in that they have well maintained tool chains and good library support freely available either directly by language authors or from a third party.
- coldtea 9y ago>I think we all agree if we could program with simple functions that each do one thing and one thing well then combine those functions makes for a much simpler language and easier to think about. Well, I don't agree. You could end up with tons of small functions, and complex interactions between them (whether they are pure or not) than make for spaghetti logic. I also don't see how Ada's pre/post conditions make it more difficult to program. More tedious, maybe, but about as much as writing tests. Not more difficult as in conceptually more challenging. As for the Ariane error, Ada could have prevented it, if it was left to -- but the programmers didn't let it. It's not a silver bullet of course, but nothing is, not even formally proven programs. Finally, the overhead is true, but some domains don't need much speed anyway, and for others, you could always have the checks for all demo/dev runs and drop them for the final production output.
- Xophmeister 9y agoIs Ada losing ground to dependently typed languages, or are these still too "academic" for production use?
- Raphael_Amiard 9y agoAda as an ecosystem has it's own alternative, SPARK. It's not a dependently typed language, but you can go just as far with it using pre and post conditions, and ghost code, insofar as what you can prove. You can see here for more information: http://www.spark-2014.org/ http://www.spark-2014.org/ http://docs.adacore.com/spark2014-docs/html/ug/en/tutorial.html http://docs.adacore.com/spark2014-docs/html/ug/en/tutorial.h...
- mhd 9y agoDoes someone have experience with Ada 2012s Design By Contract support (including tooling, preferably for GNAT)? Eiffel is yet another Pascal-ish language whose passing I lament, and lately I've been seriously considering giving Ada another try, given that Modula-3 and Oberon won't exactly come back to life miraculously, and I'm still a bit dubious about all the new kids on the block.
- kqr 9y agoIn a hobby capacity, yes. It's hard to go back to programming without contracts and invariants once I've had a taste for it.
- nraynaud 9y agoI wanted to use Ada for a personal project, it's not what it's cracked to be. Some registers are hard to map in the language. The timing side of things is extremely misleading: there are time primitives in the language, but you don't know if the implementation of the runtime will actually reach your constraint, and you won't be warned (it took me 2 days on the scope before understanding that it was not my code that was the issue). if you want to toy around, I have started an Intellij Plugin: https://github.com/nraynaud/ada-intellij https://github.com/nraynaud/ada-intellij Some registers of the STM32 are mapped here: https://github.com/nraynaud/bldc_ada/tree/master/src https://github.com/nraynaud/bldc_ada/tree/master/src
- bitwize 9y agoPuppy 1: And so, in conclusion, we have determined that Ada provides sufficient safety guarantees and features for our embedded system needs. Any questions? Puppy 2: Yes, I have a question. Why didn't you use Rust? Puppy 1: That's a good question. While Rust looks promising, we felt it was too immature for our needs and decided to go with the time-tested, standardized semantics and extensive tooling available with Ada. Puppy 2: Rust has a borrow checker. That makes it 100% safe. Puppy 1: Leaving aside the fact that no language is 100% safe, safety is a complicated topic and you can't make strong statements like that about it. Does Rust's borrow checker enforce arbitrary program invariants? Puppy 2: ...Rust has a borrow checker. That makes it safe. Borrow semantics is the secret ingredient in the memory safety sauce.
- eutectic 9y agoDon't you find it's so much easier to argue against yourself? None of those pesky unpredictable arguments to worry about.
- bitwize 9y agoYou do realize that that wasn't intended to be a serious argument about the points of Ada vs. Rust... right? Have you seen "MongoDB is web scale" (https://youtu.be/b2F-DItXtZs https://youtu.be/b2F-DItXtZs)?
- jcadam 9y agoI worked with Ada for several years on a military satellite program (simulator software for various satellite subsystems). Specifically, I was using Ada95 on SPARC/Solaris, and later got to work on a project (with a different employer) to port much of the same system to x86/Linux with Ada2005 (so many endian issues :shudder:). This was in the mid-late 2000s. I remember when I told my mother (also a software engineer) that I got a job using Ada, she laughed and handed me all of her old Ada83 books (which are still on my bookshelf at work). I'm doing backend services in JVM-land these days, which I enjoy a bit more (not to mention I'm building a more portable skill-set) :)