Live data from Hacker News

An intro to Zig's integer casting for C programmers

lagerdata.com

101–110 of 135 posts

Re: An intro to Zig's integer casting for C programmers

#101
post #11
post #7

Earlier quoted context omitted.

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

> 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 progra…

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

#102

Earlier quoted context omitted.

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.

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.

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

#103
>You won't even get a warning unless -Wextra or -Weverything is turned on.

I know people are used to languages where compiler warnings are on by default, but if you are building C without -W/-Wextra you are kind of asking for trouble. -Weverything is probably too pedantic for most people but -Wextra is pretty much required. And -Werror is required for projects where discipline can't be assumed or where the build log is bigger than a screenful.

Re: An intro to Zig's integer casting for C programmers

#104
post #58

I am curious to know the reasons behind the @as() syntax. What's wrong with "i32 y = (i32) x;"? I look with interest to new languages but after so many years dealing with C, my parser crashes when I see the type after the variable name and at the end of functions declarations. var x : u8 = 5; What's wrong with "u8 x = 5;"? And I don't really like type inference very much (or when it's abused or cannot be avoided). Wh…

remove "pub" from your godbolt. Zig/godbolt is identifying that you're trying to build a full program and so it brings in a lot of the boilerplate necessary to launch a program (for example, the panic handler, stdlib stuff to format strings for the panic handler, etc).

On the other hand, leave out “pub” and Zig won’t compile it…

Re: An intro to Zig's integer casting for C programmers

#105
post #10

Earlier quoted context omitted.

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'v…

> 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.

[deleted]

Re: An intro to Zig's integer casting for C programmers

#106
post #5

Earlier quoted context omitted.

D doesn't try to "fix" C integer promotion/casts. It's because they aren't bad defaults. As a bonus you can port code from C with less risk. Soon you'll be able to compile it directly. I contributed to found the only discrepancy in D vs C code wrt integer (-byte would yield byte instead of int), and it was fixed so that they match exactly C _conventions_.

C integer promotions are what remains of old computers systems which couldn't handle anything but a 'word'. It result in things highly inconsistent on modern 64-bit machines: For example, char/short are automatically promoted to int or unsigned int when an operation is performed on them, but this doesn't happen between int and long. Simple things like adding two int16_t together to get a int16_t in return is really h…

It should be noted that Zig’s int promotion rules are currently broken though.

Re: An intro to Zig's integer casting for C programmers

#107
post #85

Earlier quoted context omitted.

> 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.

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 "Rea…

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

#108

Earlier quoted context omitted.

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.

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.

No tests? How do you refactor while ensuring your business logic invariants?

Re: An intro to Zig's integer casting for C programmers

#109

Earlier quoted context omitted.

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.

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 easie…

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

#110

Earlier quoted context omitted.

Thanks!

No problem! You might find this website useful, too, as it is filled with resources: https://www.adaic.org/learn/materials/

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.

Post reply on HN