News for hackers. Stuff that matters.
Re:An intro to Zig's integer casting for C programmers by lionkor on Tuesday May 11, 2021 @08:50AM (#27117442)
> If runtime safety is turned off, you get undefined behavior

You already know someone will teach their students to always have it off because its "slower" or something.

Make something idiot-proof and the world invents a better idiot.

Another language that does safety like this incredibly well is Ada (Ada/SPARK), and I'm unsure why people aren't more hyped about it. So many people hype Rust or Zig or whatever new language, and yet there's an incredibly safe and expressive language that's used in high-reliability applications like missile guidance systems, that nobody seems to talk about.

Re:An intro to Zig's integer casting for C programmers by gilnaa on Tuesday May 11, 2021 @09:42AM (#27118012)
Not to sound too aggressive, I'm not sure why ada programmers keep being surprised at the hype.

Safety (of all kinds) is not the only selling point of Rust and Zig, and the fact that Ada also have safety measures doesn't mean that it's instantly an option for me.

For example, I keep seeing people hype about Zig/Rust, for all kinds of reasons; and the way that they present their arguments is very compelling. While I've heard of Ada before, AFAICT the only context in which it is brought up is to downplay hype over Rust/Zig; never as a standalone.

Sounds like a PR problem, mostly.

EDIT: Not to say that there aren't other problems, just saying that this point alone isn't some magic bullet.

I don't like Rust because it gives me memory safety, tons of languages do that. I love Rust because the tradeoffs it gives me worth the switch, and the overall tooling and ecosystem are very well made.

Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @11:38AM (#27119416)
> Sounds like a PR problem, mostly.

It's the case that the Zig creator did put a high priority on soft "PR" for the language, the first hire was a developer advocate/community manager. I think this is a great case of "lessons learned" from the history of programming languages.

Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @11:24AM (#27119205)
> I don't like Rust because it gives me memory safety, tons of languages do that. I love Rust because the tradeoffs it gives me worth the switch, and the overall tooling and ecosystem are very well made.

Same applies to the tooling of Ada/SPARK, but as you have said, it is pretty much a PR issue.

Re:An intro to Zig's integer casting for C programmers by c-cube on Tuesday May 11, 2021 @03:11PM (#27122203)
I'm not saying it's justified, but I think the syntax is also a big impediment (just like for my daily driver, OCaml). Ada looks pretty verbose and annoying to write code in, at least if one wants to use it for side projects, small utilities, etc. rather than spaceship firmware; and that's probably how a lot of languages become popular, you need to tinker with them on small things.

OCaml has seen the alternative "Reason" syntax (JS-like) grow in popularity. Maybe a C-like (or better, rust-like) syntax for Ada would help the language's adoption. People already using Ada would complain that the current syntax is fine but they're not the target demographic :-)

Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @07:26PM (#27124902)
My opinion: I really dislike Rust's syntax because to me it is similar to Perl's that I also do not like that much as I do not know what is happening just by looking at it (I still like to use Perl here and there, but these days I lean towards Tcl more), it seems hidden from me, even compared to something as C where I have to think about conversions and whatnot.

I can easily read and understand someone's Ada, C, or OCaml code and actually know what is going on, but I cannot read and understand even my own Perl code (after a week or two), or other people's Rust code. I would rather prefer reference implementations to be in C than in Rust, too. If I read the C version, I can easily port it to any language vs. if it were in Rust.

Re:An intro to Zig's integer casting for C programmers by c-cube on Wednesday May 12, 2021 @11:57AM (#27131799)
Thank you for the answer :-). I'm still surprised because to me, Rust looks a _lot_ like OCaml with curly braces. The surface lexical conventions are mixed with C++ (like `::` for namespacing) but code still looks more like OCaml than C, with `let` bindings, sum types, expressions, `match` being omnipresent. Even the type annotations look more ML-ish than the type-first C convention. I fail to see the relation to perl (there's barely any `$` in rust code! and most sigils are still the & related to references that also abound in C).
Re:An intro to Zig's integer casting for C programmers by johnisgood on Wednesday May 12, 2021 @09:02PM (#27137249)
I compared it to Perl because of its heavy use of symbols in general. In Rust, you can have 6 symbols next to each other and that is valid code. See below.

OCaml does not look like Rust to me (OCaml seems more consistent, and Rust seems like a mixed bag of everything to me). It does not hide as much behind symbols for example as Rust does, I think, and learning it was really easy. I tried to read Rust, I really did, but everything is so hidden from me. I did not mean to say that any of the mentioned languages are anywhere close to C though. In any case, if I had to look at reference implementations, C would be the best (to me). It is really easy to know what is going on and why, and thus it is easy to implement it in any languages I know. Probably because it is not a language with many high-level abstractions or language constructs (syntactic sugars) that hide what is going on.

Example snippets as to why I dislike Rust:

  let mut parents_array = ArrayVec::<[&[u8; BLOCK_LEN]; MAX_SIMD_DEGREE_OR_2]>::new()

  let input_ptrs: &[*const u8; DEGREE] = &*(inputs.as_ptr() as *const [*const u8; DEGREE]);
And this is nothing, there are much worse ones, and I would have to give you files for that, but pretty much any famous Rust project is difficult to read for me. I really do not understand most Rust code, I wonder if the problem is with me.
Re:An intro to Zig's integer casting for C programmers by ksec on Tuesday May 11, 2021 @04:45PM (#27123285)
> Ada looks pretty verbose and annoying to write code in,

I still dont understand this, you spend 80% of the time thinking about code, 19% reading, and 1% typing.

Re:An intro to Zig's integer casting for C programmers by c-cube on Tuesday May 11, 2021 @06:00PM (#27124106)
I don't have this experience. I like to prototype by writing code (or type signatures), and then refactor a lot from the initial solution. That's easier to do if the syntax is reasonably concise (the other half is to have good types which Ada definitely provides).
Re:An intro to Zig's integer casting for C programmers by jstimpfle on Tuesday May 11, 2021 @05:28PM (#27123753)
80% thinking when you're stuck and don't know who to ask. I've made the same mistake. Have you watched some streamers? They are prototyping by typing, I would say, 50% of the time.
Re:An intro to Zig's integer casting for C programmers by mousepilot on Tuesday May 11, 2021 @05:14PM (#27123614)
I never used Ada, but read a book on it.

I don't even remember much, just that how much I loved just the look of the example programs, but that was during community college when I was new to programming. It wasn't part of a class, but the guy who implemented the curriculum just jammed the library with jewels and the entire library collection was just full of classics especially since the actual curriculum was just a basic associates in "business data processing."

Re:An intro to Zig's integer casting for C programmers by elcritch on Tuesday May 11, 2021 @12:46PM (#27120339)
From what I can tell, safety isn't a selling factor of Zig. From a "safety" perspective Zig seems like a step backwards compared to the latest generation of languages, and Rust in particular. Zig's ergonomics seem decent but its memory safety tact appears to basically be to include valgrind-like tools into debug builds with good PR.
Re:An intro to Zig's integer casting for C programmers by rslabbert on Tuesday May 11, 2021 @05:07PM (#27123535)
Not a Zig expert, but safety is a factor for Zig, it just treats it as less of an absolute than Rust. I think the thing to keep in mind is that something can be a priority without being an absolute priority. I'd make a comparison to OpenBSD vs Linux. Both have security as a priority, OpenBSD just has a more absolute focus on it.

For example, a couple of features come together really nicely to make memory safety easier to test in Zig: * You need a reference to an Allocator to be able to allocate memory, so as a general rule, the caller can control which allocator is used. * Unit testing is integrated well into the language. * Therefore, you can create an allocator for each unit test, and fail the test at the end if any memory was leaked. * This process can also happen at the application level with the General Purpose Allocator, which can let you print an error when the program exits if anything was leaked.

The above doesn't solve every memory safety problem (and there are other features like native bounds-checked slices that solve other kinds of issues), but it provides an extra layer that can probably get us quite far into the "quite safe" camp.

Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @09:21PM (#27125623)
This. AFAICT Memory leaks are not practical to test in rust (note this is not the same as detectable), but basically come for free in zig tests.
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @01:45AM (#27127030)
Except that level of security I could already do with Pascal dialects like Turbo Pascal or Modula-2, hence why I really don't see much value in Zig, other than being more appealing to younger generations.
Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @01:06PM (#27120569)
Putting valgrind into the stdlib is really clever, and also, I like memory safety being the carrot to get you to write tests. I worry having a 'safe' system like rust sometimes causes very smart (TM) developers, especially less experienced ones, to be complacent and write less tests.
Re:An intro to Zig's integer casting for C programmers by nicoburns on Tuesday May 11, 2021 @06:25PM (#27124371)
Writing fewer tests is somewhat justified when you can encode invariants in the type system. It depends on the level of reliability you require of course. But my Rust code without tests has been comparably reliable to my code in other lanaguages eith tests.
Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @07:50PM (#27125051)
No tests? How do you refactor while ensuring your business logic invariants?
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @09:40AM (#27130192)
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @01:42AM (#27127017)
Back when Ada was as young as Rust and Zig, we only had magazines like BYTE and Dr Dobbs, and BBSs for driving hype.

There were no free beer compilers and no 8/16 bit home computer was capable of hosting an Ada compiler, Basic, Pascal and Modula-2 was the best they could manage.

Re:An intro to Zig's integer casting for C programmers by gilnaa on Wednesday May 12, 2021 @07:11AM (#27128947)
Sorry to hear that
Re:An intro to Zig's integer casting for C programmers by nine_k on Tuesday May 11, 2021 @10:29AM (#27118507)
Ada / spark may be a great thing. But how do people know?

Is there a good compiler that one can install for free?

Are there a few good and comprehensive books / references / guides, available online for free?

If you want something to become popular, give it away. Ideally, push it. At the very least, have a limited free version. Or turn a bling eye to small-time piracy, as many vendors did for a long time. Or make it dead easy to buy it for $10.

(None of the above works for you? Sorry, you have just turned down 99% of kids who might like to tinker with your tech, love it, and then promote it wherever they go. Your tech may be hot and desired in the narrow circle of pros, but it's not going to become popular and win the world.)

Re:An intro to Zig's integer casting for C programmers by roblabla on Tuesday May 11, 2021 @11:00AM (#27118877)
Not sure why you think ADA/Spark isn't free. There's GNAT[0], an open source ADA compiler that's part of the GNU toolchain, a fairly good book teaching ADA and SPARK[1] by Ada Core, and plenty of tutorials.

Accessibility is really not the problem. The problem is, Ada is an old language that has many similar problems to C: lack of a good package management story, and a design by committee making language evolution glacially slow (though that also doubles as a feature). It also lacks a vibrant ecosystem like we can find in other popular languages.

Furthermore, SPARK in particular takes the concept of safety much further than Rust or Zig do right now, as it allows proving the correctness of a program according to a formal specification. Rust/Zig only care about proving the absence of UB. This makes SPARK much more complex, and thus have a much higher barrier of entry.

[0]: https://www.gnu.org/software/gnat/

[1] https://learn.adacore.com/index.html

Re:An intro to Zig's integer casting for C programmers by ModernMech on Tuesday May 11, 2021 @12:02PM (#27119769)
Your first link pretty much says it all: barebones website 5 years out of date, no docs, no resources, no community links, no indication that this project is even alive. To top it off the project is named after one of the most annoying creatures on the face of the Earth. This is a marketing issue.

The problem for older languages is that the bar for what's expected of a language has risen substantially. A long time ago, languages weren't even expected to have implementations. Today, not only are implementations expected for all major platforms, languages are also expected to run on phones and the browser, include package managers and library repositories, have a language server implementation and editing modes for all major IDEs, be open source with active development, provide extensive documentation on the scale of a book, and also promote a vibrant and active community. Oh, and to top it off, users don't want to pay for any of that. It's just expected, which is why most languages these days only come out of large tech companies that can afford to fund all of the above with no expectation of profit.

Re:An intro to Zig's integer casting for C programmers by MaxBarraclough on Tuesday May 11, 2021 @03:12PM (#27122221)
> Your first link pretty much says it all: barebones website 5 years out of date, no docs, no resources, no community links, no indication that this project is even alive.

A better starting point might be http://www.GetAdaNow.com/

Re:An intro to Zig's integer casting for C programmers by xfer on Tuesday May 11, 2021 @01:39PM (#27121020)
Judging the state of affairs there might as well go with ATS. http://www.ats-lang.org/
Re:An intro to Zig's integer casting for C programmers by nobodywasishere on Tuesday May 11, 2021 @10:43AM (#27118663)
There's an Ada compiler as part of gcc.

The most prominent project that i know of written in ada is ghdl.

Re:An intro to Zig's integer casting for C programmers by greatgoat420 on Tuesday May 11, 2021 @10:58AM (#27118854)
There was at least always the recommendation to only use the version of the Ada compiler released by the FSF as the regular GCC one is/was more encumbered.
Re:An intro to Zig's integer casting for C programmers by nobodywasishere on Friday May 21, 2021 @12:38PM (#27236324)
Are they not the same thing?

https://en.wikipedia.org/wiki/GNAT

Re:An intro to Zig's integer casting for C programmers by AnIdiotOnTheNet on Tuesday May 11, 2021 @09:17AM (#27117698)
> Make something idiot-proof and the world invents a better idiot.

Sure, but if you only ever give people safety scissors then you're severely limiting the kinds of things that they can build. You have to let people who know what they are doing be able to do what they need to do, so you have to be able to turn the runtime safety off. Zig can do this at the scope level.

Re:An intro to Zig's integer casting for C programmers by lionkor on Thursday May 20, 2021 @04:29AM (#27218769)
In my mind this isn't about safety scissors at all. I hate languages that in any way limit the kind of code I want to write, which is why I write C++ for the most part, but that's another rant for another day.

If you dont want full control like in C++, a language would be nice that has one specific style, one specific way to do things, and so on. Go(lang) is quite close to this, in my experience. You can't do thread safety wrong, because there's only really one way, and so on.

I would love a language with

1. Explicit nullable types (not like Java's "anything can be null" design), so everything is a non-nullable reference type unless its "optional<T>" for example. I strongly support the idea of a nullable type only being used where it being null carries information.

2. Strong typing - like, tungsten strong. Implicit conversions need to be compiler errors, no implicit constructors, etc. with simple explicit casting

3. One style - and it better not be Java-like forced-OOP.

4. Full and clear memory control, RAII support, no gc. I need my RAM for other stuff.

I'm not sure if there's a language like that out there. I don't care for library support, I just want a fun language.

Re:An intro to Zig's integer casting for C programmers by TchoBeer on Tuesday May 11, 2021 @11:06AM (#27118949)
I don't understand why there aren't any solutions like this. Why aren't there any languages with a good garbage collector but also let you turn it off and work with memory manually. Maybe there is and I don't know of it? Maybe garbage collected languages and manual memory languages require different design? I don't know.
Re:An intro to Zig's integer casting for C programmers by arc619 on Tuesday May 11, 2021 @12:29PM (#27120140)
Nim is built like this. The gc is opt-in by type and manual memory management is simple. All other types are stack allocated by default.

The new gc is pretty much compiler assisted scope managed smart pointers as well. Also when using the gc you can build your own types with custom create/free/copy/move operators to do what you want without worrying about a stop the world gc.

Using the arc gc pretty much compiles down to what you'd do manually. For cycles you can use the orc gc, again it's all opt in.

I find this a great balance of productivity and performance, where it's easy to have high control when you want it, and still get good performance when you're not bothered.

Re:An intro to Zig's integer casting for C programmers by elcritch on Tuesday May 11, 2021 @01:06PM (#27120571)
+1 for Nim and being usable without a GC or for manual memory management like dealing with C apis. Though to be fair, quite a few types in the stdlib are heap based. But you can make your own static heap pool.

With the new ARC & move semantics, Nim has hit a sweet spot, IMHO. It's like the language struggled to find a fit for a long time. But ARC allows very low overhead memory safety, perfect for mcu's and wasm in particular.

Though perhaps Swift could be a contender in this arena as well with its ARC, but it's development is so Apple centric.

What's interesting to me is that with move semantics and smarter compiler analysis, an ARC based GC overhead approaches that of Rust's compile time lifetime memory management. For any non-trivial program Rust seems to use a lot of Rc's or copies to get around lifetime analysis issues. So if the compiler can automatically figure out lifetimes in code it can eliminate many ARC operations.

I hope more languages adopt more flexible ARC based gc's or improve on rusts ergonomics.

Re:An intro to Zig's integer casting for C programmers by kaba0 on Tuesday May 11, 2021 @11:20AM (#27119155)
Well, GC languages can’t really allow arbitrary pointer arithmetic (because it would make GC useless/unsafe), but languages that can do explicit stack—allocation are numerous, like C#, Go, I’m sure D as well. Nim also has an optional GC, so there are languages all around the spectrum.
Re:An intro to Zig's integer casting for C programmers by dnautics on Tuesday May 11, 2021 @11:40AM (#27119447)
for erlang, if you drop down to C you completely lose the garbage collector, but the docs for doing this show you how to set up a hook for your memory to be garbage collected just like any other first-class data in the system.

If you're really responsible, it's possible to use the system allocator to inform the system about how much memory your allocations consume so that the memory pressure triggers have a correct accounting of how much memory is being used.

Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @01:51AM (#27127059)
You can use value types and do manual memory management in C#, F#, VB, D, Nim, Swift (RC is GC).

Then on the past languages that failed to gain steam, Mesa/Cedar, Modula-2+, Modula-3, Oberon, Oberon-07, Oberon-2, Active Oberon, Eiffel, Sing#, System C#, Component Pascal, among many others.

The only thing missing is that many are badly taught, use new everywhere and don't bother to fully understand all language features.

Re:An intro to Zig's integer casting for C programmers by june11 on Tuesday May 11, 2021 @02:47PM (#27121923)
dlang has exactly this, with both marking functions as @nogc and being able to both use the gc in one block, and malloc free in the next. You can also limit D a subset called 'BetterC'. I Really enjoy being able to gc my way though a problem until I need some explicit memory structure for putting together a ECS or similar memory management heavy patterns.
Re:An intro to Zig's integer casting for C programmers by bitmapper on Wednesday May 12, 2021 @12:27AM (#27126578)
My favorite example of this is probably Clean, which solves this using uniqueness types. You can have unique values that are managed using compile time memory management, but also are free to use garbage collected values.

It makes for a very performant pure functional language. My only gripe is that the stdlib is abysmal, and hardcoded into the compiler.

Re:An intro to Zig's integer casting for C programmers by Narishma on Tuesday May 11, 2021 @04:25PM (#27123045)
I think this will just lead to a split ecosystem with some libraries requiring a GC and others requiring manual memory management.
Re:An intro to Zig's integer casting for C programmers by ArtifTh on Tuesday May 11, 2021 @11:15AM (#27119080)
C# has GC by default, but you can do manual memory management in "unsafe" blocks
Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @02:09AM (#27127178)
You can also do manual memory management in safe code.

- value types

- stackalloc is safe since C# 7

- SafeHandles since C# 2.0

- IDispose interface

- IDispose like Dispose() since C# 8

- Marshal class since C# 1.0

- Span<>() classes since C# 7

Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @05:15AM (#27128305)
Forgot to mention:

- static lambdas since C# 9

- native function pointers since C# 9

Re:An intro to Zig's integer casting for C programmers by dapids on Tuesday May 11, 2021 @02:07PM (#27121407)
Yes, sure, but have you actually used Ada in practice? It's not exactly ergonomic or straightforward either, it's not magic.

You don't hear about the struggles of using it in practice because the projects you've pointed out are usually confidential.

In my experience MISRA is a much more popular standard for secure programming in the defence industry versus Ada. MISRA is a C standard, and yes, it runs missile systems, Boeing braking systems, you name it.

Re:An intro to Zig's integer casting for C programmers by pjmlp on Tuesday May 11, 2021 @09:37AM (#27117954)
Or Modula-2, NEWP, BASIC, or really most languages that aren't copy paste compatibel with C.

Ada suffered from its domain, original price of compilers, and the few UNIX vendors that cared to offer compiler like Sun, it was an additional acquisiation on top of UNIX SDK.

Everyone knows that only newbies do coding errors in C, so why spend the extra money? /s

Re:An intro to Zig's integer casting for C programmers by kjs3 on Tuesday May 11, 2021 @06:18PM (#27124302)
few UNIX vendors that cared to offer compiler like Sun, it was an additional acquisiation on top of UNIX SDK.

The Sun C compiler was an additional cost item, just like everyone else.

Re:An intro to Zig's integer casting for C programmers by pjmlp on Wednesday May 12, 2021 @01:23AM (#27126903)
Indeed, so if you already had to pay for C which is a required language on any UNIX, there is no way around it, why spend the extra dollars for Ada just to feel good?

That was my point.

Re:An intro to Zig's integer casting for C programmers by kjs3 on Wednesday May 12, 2021 @12:14PM (#27131987)
Because it's a better language for a lot of use cases? But I concede that the history of the industry indicates that "don't care" is the norm.
Re:An intro to Zig's integer casting for C programmers by tored on Tuesday May 11, 2021 @10:34AM (#27118571)
Is anyone actively using Modula-2? Actively as in starting new projects, compiler improvements, tooling, community etc.
Re:An intro to Zig's integer casting for C programmers by pjmlp on Tuesday May 11, 2021 @10:51AM (#27118764)
The GNU M2 compiler is kept up to date with GCC, it is just kept out of tree.

https://www.nongnu.org/gm2/homepage.html

However I doubt the language gets much use nowadays beyond some legacy code bases, its opportunity is now gone.

Re:An intro to Zig's integer casting for C programmers by qayxc on Tuesday May 11, 2021 @09:49AM (#27118103)
> Everyone knows that only newbies do coding errors in C, so why spend the extra money? /s

The Ariane 5 maiden flight disaster illustrated quite clearly that the choice of language has little influence on the actual correctness of a program.

Ada on its own is no better than Pascal in that regard. A formally verified and thoroughly tested MISRA C program can be safer and more correct than a sloppily written Ada program.

So the question is indeed not as rhetorical as one might think - why spend the extra money indeed? Isn't it better spent on verification, testing, tooling and culture, which benefits the development regardless of programming language?

Re:An intro to Zig's integer casting for C programmers by pjmlp on Tuesday May 11, 2021 @10:04AM (#27118240)
Ariane 5 error was caused by the remaining 30% programming errors when we leave out the 70% of software failures caused by C typical errors.

So yes, it is quite worthy to reduce the amount of money spent in verification, testing, tooling and culture.

The alternative is to just give up that programmers will never learn and just force verification at hardware level, like Google is doing on Android.

"Memory Tagging for the Kernel: Tag-Based KASAN"

https://www.youtube.com/watch?v=f-Rm7JFsJGI

Oracle on Solaris SPARC,

https://docs.oracle.com/cd/E37838_01/html/E61059/gqajs.html

Apple on iOS,

https://developer.apple.com/documentation/security/preparing...

Microsoft on Azure Sphere,

https://www.microsoft.com/security/blog/2020/11/17/meet-the-...

Re:An intro to Zig's integer casting for C programmers by messe on Tuesday May 11, 2021 @10:31AM (#27118534)
Ironically enough, I recall reading that if the overflow hadn't triggered a hardware exception and instead was silently ignored, the first stage would have survived; the code in question had just been carried over from Ariane 4 and was no longer important for the operation of the booster..
Re:An intro to Zig's integer casting for C programmers by vlovich123 on Tuesday May 11, 2021 @10:41AM (#27118652)
That’s not an alternative to memory safety. That’s just a basic security measure even if you write everything in a safe language like Rust or Zig (let alone the fact that you have enormous C/C++ legacy codebases that are likely still seeing ongoing development due to switching costs). The reason is you will always have some amount of unsafe code when dealing with the hardware and this is a hardening measure to protect against slipups.
Re:An intro to Zig's integer casting for C programmers by kjs3 on Tuesday May 11, 2021 @06:23PM (#27124352)
No. The Ariane 5 disaster was caused by a development team deliberately turning off safety checks. Ada is in all regards a 'safer' language than Pascal, as long as you don't disable the safety features.

http://www-users.math.umn.edu/~arnold/disasters/ariane5rep.h...

http://www.adapower.com/index.php?Command=Class&ClassID=FAQ&...

Re:An intro to Zig's integer casting for C programmers by butterisgood on Tuesday May 11, 2021 @10:02AM (#27118218)
I think I'd like to get into Ada more, but I'm always a bit unsure on how to select the right toolchain (is the Dragonegg/LLVM option viable today?) etc.

I would love to see something like "Rustlings" for Ada, as I found that was a good way to practice not only writing code, but reading it as well.

I was able to self-teach Haskell and Erlang without any major problems, and even managed to ship applications written in it commercially.

Re:An intro to Zig's integer casting for C programmers by pjmlp on Tuesday May 11, 2021 @10:10AM (#27118295)
Plenty of learning paths at https://learn.adacore.com/
Re:An intro to Zig's integer casting for C programmers by butterisgood on Tuesday May 11, 2021 @10:44AM (#27118672)
Thanks, I'll check it out!

(Looks like I found a use for the new Rosetta on my M1 Mac.... I wonder when there will be builds for aarch64 for Darwin)

Re:An intro to Zig's integer casting for C programmers by StreamBright on Tuesday May 11, 2021 @10:53AM (#27118791)
> Make something idiot-proof and the world invents a better idiot.

:D

My argument is that if I need that insane speed and safety features have to be off I should actively work for that not the other way around that I should actively work for safety.

Why? Because we forget to do things.

> Another language that does safety like this incredibly well is Ada (Ada/SPARK)

I wanted to learn Ada for a long time. Do you have a guide or tutorial how to get into it?

Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @11:32AM (#27119333)
I once collected all of my posts about Ada which do contain lots of links that can get you started. I will not re-post them here, instead you may go to https://news.ycombinator.com/item?id=23808305. Check out the links under [2].

Especially these ones: https://news.ycombinator.com/item?id=21435869 and https://news.ycombinator.com/item?id=21437498

Re:An intro to Zig's integer casting for C programmers by StreamBright on Tuesday May 11, 2021 @11:53AM (#27119642)
Thanks!
Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @12:00PM (#27119742)
No problem! You might find this website useful, too, as it is filled with resources: https://www.adaic.org/learn/materials/
Re:An intro to Zig's integer casting for C programmers by mousepilot on Tuesday May 11, 2021 @09:59PM (#27125826)
I loved reading about ada back in the day, how is it nowadays wrt network programming. I'm checking out gnat.sockets, does it have a snappy select() type thing like linux's epoll?

Sorry if a lazy question, last time I looked at ada was decades ago and I'm surprised to find enthusiasts for it on HN.

edit: an advantage for c is that you can get loads of examples just googling, sucks for less used languages I guess.

Re:An intro to Zig's integer casting for C programmers by johnisgood on Wednesday May 12, 2021 @12:14AM (#27126515)
It has been a while, but you may want to look at:

- https://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT... (search for "C select()")

- https://www.codelabs.ch/anet/

- https://github.com/samueltardieu/adasockets

- https://github.com/rtyler/ada-playground/blob/master/epollec...

Some old reading: https://brokenco.de/2013/04/07/async-with-ada.html

You may want to check how GNAT.Sockets and Anet are implemented, too. I know that GNAT code is heavily documented.

Re:An intro to Zig's integer casting for C programmers by mousepilot on Wednesday May 12, 2021 @05:15AM (#27128301)
thanks man, your post is a great timesaver, that wikibooks link itself is packed with info!
Re:An intro to Zig's integer casting for C programmers by johnisgood on Thursday May 13, 2021 @02:12AM (#27138982)
Of course, you are welcome!
Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @09:38AM (#27117970)
Re:An intro to Zig's integer casting for C programmers by steveklabnik on Tuesday May 11, 2021 @10:27AM (#27118477)
Most of Rust's checks are at compiletime, and Ada employs runtime checks as well.
Re:An intro to Zig's integer casting for C programmers by johnisgood on Tuesday May 11, 2021 @11:18AM (#27119120)
It can employ, but you do not have to (you can turn off all runtime checks and use formal verification only, something that Rust cannot do (statically verify correctness the same way you can with SPARK using GNATprove)), it can all be done at compile-time with Ada/SPARK.

> These runtime checks[1] are costly, both in terms of program size and execution time. It may be appropriate to remove them if we can statically ensure they aren't needed at runtime, in other words if we can prove that the condition tested for can never occur.

> This is where the analysis done by GNATprove comes in. It can be used to demonstrate statically that none of these errors can ever occur at runtime. Specifically, GNATprove logically interprets the meaning of every instruction in the program. Using this interpretation, GNATprove generates a logical formula called a verification condition for each check that would otherwise be required by the Ada (and hence SPARK) language.

Additionally, in Ada/SPARK, you can formally verify tasks (concurrency), too: https://docs.adacore.com/spark2014-docs/html/ug/en/source/co....

Moreover:

> SPARK builds on the strengths of Ada to provide even more guarantees statically rather than dynamically. As summarized in the following table, Ada provides strict syntax and strong typing at compile time plus dynamic checking of run-time errors and program contracts. SPARK allows such checking to be performed statically. In addition, it enforces the use of a safer language subset and detects data flow errors statically.

Contract programming:

- Ada: dynamic

- SPARK: dynamic / static

Run-time errors:

- Ada: dynamic

- SPARK: dynamic / static

Data flow errors:

- Ada: -

- SPARK: static

Strong typing:

- Ada: static

- SPARK: static

Safer language subset:

- Ada: -

- SPARK: static

Strict clear syntax:

- Ada: static

- SPARK: static

Additionally, safe pointers in SPARK: https://blog.adacore.com/using-pointers-in-spark and https://arxiv.org/abs/1710.07047.

More information about Get_Line (i.e. even where you would think you cannot go static): https://blog.adacore.com/formal-verification-of-legacy-code.

[1] overflow check, index check, range check, divide by zero

Re:An intro to Zig's integer casting for C programmers by majjgepolja on Tuesday May 11, 2021 @11:04PM (#27126135)
> You already know someone will teach their students to always have it off because its "slower" or something.

Already happening with Nim.

But I'd expect a system programmer to know better. When to use release and when to use development mode.

Case in point, rust doesn't catch integer overflows in release build either. Maybe Efficiency is more important than we think?

Re:An intro to Zig's integer casting for C programmers by 2526702934 on Tuesday May 11, 2021 @10:52AM (#27118767)
> there's an incredibly safe and expressive language that's used in high-reliability applications like missile guidance systems, that nobody seems to talk about.

Maybe because they assume that it's only used for that purpose? You talk about rocket science and you expect people to jump on the bandwagon...

Re:An intro to Zig's integer casting for C programmers by petre on Tuesday May 11, 2021 @10:55AM (#27118816)
> incredibly safe […] high-reliability applications like missile guidance systems

https://en.m.wikipedia.org/wiki/Cluster_(spacecraft)

Re:An intro to Zig's integer casting for C programmers by sigzero on Tuesday May 11, 2021 @05:10PM (#27123570)
Yup, people are the issue.