Live data from Hacker News

Better C – A subset of D Programming Language

dlang.org

241–250 of 360 posts

Re: Better C – A subset of D Programming Language

#241

Earlier quoted context omitted.

no ? there are plenty of maps which don't return something which looks like [a] -> [b].

So? They still have a type, it doesn't have to be "screw you figure it out yourself". Functor f => (a -> b) -> f a -> f b

I have seen few videos by Walter Bright, Andrei Alexandrescu on ranges and I have no problem understanding D`s documentation. Maybe you should learn the language before using it.

Re: Better C – A subset of D Programming Language

#242
post #230

Earlier quoted context omitted.

Just a couple of ways how it is better, using Turbo Pascal 7 for MS-DOS, released in 1992. - Units (modules) for separate compilation with strong type checking and not needing useless prefixes - A proper string type - Proper arrays with bounds checking, it has functions to retrieve upper and lower bounds - Allows the definition of numeric ranges - Enumerations are their own type, can be used as array indexes or data…

Unfair comparison: Turbo Pascal 7 is more like C++20.

Not really, hence why I mentioned 1992. C has had plenty of time to catch up, but apparently it wasn't something that WG14 cared about.

And it is not like many aren't actually coding in GCC C, Clang C, TI C, xlc C, aC C and so on.

Which even with those C extensions fail on the security story.

Re: Better C – A subset of D Programming Language

#243
post #45

It's interesting how this works: - enumerate everything C is doing bad. - presents fixes with a full bag of unnecessary features that no c programmer wants. I wonder why there is no "Fixed C".

Sorry to see this at the bottom of the thread, because you have a real point here. None of the attempts at "better C" or even "replacing C" have been serious attempts, and it's frankly getting a bit insulting. No one who still uses C wants its replacements to "catch up" on the past 20 years of new language development. We want C, but without the problems. We don't want D but less so. The response below - "you don't h…

While I understand the value in a small language that you can wrap your head around, I think that that is a relatively uncommon problem that real-world language developers shouldn't be catering to today (and C certainly isn't small or simple). These days, programs are simply expected to do more while not suffering from the kinds of security vulnerabilities that C code is so chock-full of. A lot of the solutions for these problems necessitate an increase in complexity.

I can understand that "you don't have to use any features if you don't want to" is somewhat silly when talking about C++, since it has so many features that can bite you when you least expect it, especially when dealing with years of legacy code. D is far better designed than C++, however; it would not take you nearly as long to learn enough D to be comfortable reading others' code.

All I'm trying to say is that "C, but without the problems" might actually look more like BetterC than you think it does. True zero-cost abstractions are clearly still an unsolved problem, but abstractions are a necessity. C's niche is rapidly disappearing.

Also, out of curiosity, what don't you like about Zig? I saw this on your website, but I couldn't find any specific issues you'd had with it.

> Wow, Zig is competitive with assembly?

> Yeah, I totally had the same reaction. I’m interested to see how it measures up under more typical workloads. People keep asking me what I think about Zig in general, and I think it has potential, but I also have a lot of complaints. It’s not likely to replace C for me, but it might have a place somewhere in my stack.

Re: Better C – A subset of D Programming Language

#244
post #190

Earlier quoted context omitted.

> However I think there are other cases where the strengths of C still add value; for instance in game development you're largely trying to do high-throughput processing over large swaths of structured data That world is dominated by C++ for the most part, though. So D's -betterC would be fighting against an incumbent that is itself also already a "better C". What value does D's -betterC bring to the table here? Skim…

I think a lot of people would argue that many C++ features, like OO, are not strictly improvements. Also C++ is a massive language, and part of the beauty of C is it's simplicity. I think what a lot of people would want is something which maintains that simplicity, but mainly delivers on basic QOL lessons we've learned in the past 40 years, like that it's nice not to have to pass around array lengths as separate vari…

You don't have to use all of C++ everywhere when programming C++.

In particular, I really love that I seldom use operator new. Objects are instantiated in the stack and object creation is ridiculously fast.

Re: Better C – A subset of D Programming Language

#245
post #34

Earlier quoted context omitted.

Yeah I think "better C" is a space which has a really good reason to exist and I'm always interested to see new entrants. IMO describing Rust as a "C replacement" is slightly off the mark because Rust's value proposition is very different from C. Rust is about giving you the best possible performance in a safe-by-default language. C is about giving you maximal control over memory, with a very thin layer of abstractio…

Rust is essentially C++ with auto-generated Move Constructors, and compiler errors on use-after-move, at the cost of preventing library developers from providing function overloads that eat temporaries as an optimization. So, yeah, really not a C replacement at all imo

Can you expand on this point of view?

I would enjoy reading a couple paragraphs, or a blog entry about this.

Re: Better C – A subset of D Programming Language

#246
post #34
post #14

D is pretty exciting. Seems like a perfect choice for those of us looking for an alternative systems programming language and are not completely convinced we'll be happy in Rust.

Yeah I think "better C" is a space which has a really good reason to exist and I'm always interested to see new entrants. IMO describing Rust as a "C replacement" is slightly off the mark because Rust's value proposition is very different from C. Rust is about giving you the best possible performance in a safe-by-default language. C is about giving you maximal control over memory, with a very thin layer of abstractio…

> C is about giving you maximal control over memory, with a very thin layer of abstraction over the hardware.

Which suggests an avenue I haven't seen anyone take yet: Pick a subset of features common to sane hardware and write a language which gives access to those features in a way which is reasonably portable and as explicit as C.

Pick a spot midway between a macro assembler and a language with a complicated optimizer and give as much access to the hardware as possible while not wedding yourself to a single ISA. Make cross-compilation a first-class feature using a module system, and error out if the programmer tries to use SIMD intrinsics when compiling for an MSP430 or something.

Re: Better C – A subset of D Programming Language

#247

Earlier quoted context omitted.

Interesting, so the return type isn't known until runtime.

When it comes to templates it's not until instantiation time - when the compiler see the code being used. So this is just an issue during compilation. The docs on static if may shed some more light: https://dlang.org/spec/version.html#staticif

So the previous code wouldn't compile unless the compiler knew what values were going to be passed into whatDoesItReturn?

Re: Better C – A subset of D Programming Language

#248

Walter here - AMA!

Hi Walter, I am a bit late to the thread but thank you for all your work and for joining this thread.

What is your vision for D/betterC/SafeD?

Is the intention at the moment to stay as a systems programming language only, or is your vision that D or betterC or SafeD gain traction as an embedded target language?

I definitely think the focus on correctness and the ease of unit testing would be great in the embedded development space.

Re: Better C – A subset of D Programming Language

#249
post #235

Earlier quoted context omitted.

the betterC form of D does not use the GC (and the compiler will let you know).

I used to be a regular on D forums. :) Yes, betterC does not use the GC, but I was speaking about the whole language, and many anti-GC folks eventually discover that they can stick to regular D and still deliver what they were trying to do. You can imagine an OS written in D, where BetterC mode gets used in the layers that for whatever reason cannot afford a GC, while all the remaning layers can happily take advantag…

Agreed. I've never felt the need to use betterC. The biggest use case I think is writing modules/libraries for other languages to use.

Re: Better C – A subset of D Programming Language

#250
post #45

It's interesting how this works: - enumerate everything C is doing bad. - presents fixes with a full bag of unnecessary features that no c programmer wants. I wonder why there is no "Fixed C".

Sorry to see this at the bottom of the thread, because you have a real point here. None of the attempts at "better C" or even "replacing C" have been serious attempts, and it's frankly getting a bit insulting. No one who still uses C wants its replacements to "catch up" on the past 20 years of new language development. We want C, but without the problems. We don't want D but less so. The response below - "you don't h…

Thanks for your comment. It's pretty normal to face this downvotes when talking about language. And my phrasing was not the most kind of all.

It's just the CS community, at some point when you are writing languages you tend to try to outsmart the language you are fixing by creating overly complex behavior. Over-engineering is every single new languages.

Even Zig fails to do better than C, I think it's syntactically a disaster.

Here is a few lines from the documentation:

  const ptr = @intToPtr(?*i32, 0x0);

  while (it.next()) |item| { /* ... */ }

  pub fn main() anyerror!void { /* ... */ }

  exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});

  const file = std.fs.cwd().openFile("does_not_exist/foo.txt", .{}) catch |err| label: { /* ... */ }
Post reply on HN