News for hackers. Stuff that matters.
Re:The cost of forsaking C by Animats on Wednesday October 05, 2016 @10:09AM (#12643916)
The industry took a giant step backwards when C displaced Pascal. The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented.

C has three fundamental issues:

1) How big is it?

2) Who owns it?

3) Who locks it?

C's lack of help in dealing with all three is the main cause of most memory-related program bugs. I once tried to fix #1 in a backwards compatible way. See [1]. After much discussion on some mailing lists, there was general agreement that this was technically feasible but not politically feasible.

(I once had hope that Rust would replace C, but Rust has gotten too fancy, with too much input from the functional programming people, the template enthusiasts, and the type theorists. Rust isn't bad, but it's at least as complex as C++.)

[1] http://www.animats.com/papers/languages/safearraysforc43.pdf

Re:The cost of forsaking C by mafribe on Wednesday October 05, 2016 @11:59AM (#12644995)

   Rust has gotten too fancy
Could you identify a simple Rust core that has all the good parts while avoiding the complexity you mention? What is superfluous in Rust?

By "templates" you mean macros? If so, how should a language implement the functionality that's currently delivered by macros?

I'm asking because I'm thinking about adding HKTs (higher-kinded types) to Rust.

Re:The cost of forsaking C by kibwen on Wednesday October 05, 2016 @12:23PM (#12645272)

  > it's at least as complex as C++
You repeat this phrase like a broken record, but have yet to back it up every time that I have asked why you have this opinion. C++ is an order of magnitude more complex than Rust.
Re:The cost of forsaking C by Animats on Wednesday October 05, 2016 @08:01PM (#12649050)
- You need templates to do anything, because the standard library uses them so heavily. They're rather opaque.

- The functional control flow style, where everything involves closures, is much harder to understand than imperative control structures.

Re:The cost of forsaking C by Manishearth on Wednesday October 05, 2016 @11:06PM (#12649931)
Generics, not templates.

They're not opaque. Templates are more opaque because of the lack of self documenting bounds, perhaps (i still wouldn't call them opaque, just more so than Rust generics)

This is the millionth time you're repeating that garbage about imperative control flow. It boils down to a use of closures in a few stdlib functions. We've had this argument before, the essence of your point is that it is different from C. Of course there is a learning curve but that is there the other way too. Once you get used to it the control flow is pretty straightforward. And in most cases you can avoid the closures and write your if or loop manually.

Re:The cost of forsaking C by Animats on Thursday October 06, 2016 @12:25AM (#12650240)
Rust's control flow primitives are coming to be defined by libraries, not the language, and tend to grow over time. For a long time, we've been able to get by with a small, well-understood set of control flow primitives, those defined by Wirth many years ago. Now we have this in Rust:

Type Option. The 2014 version.[1] The 2016 version.[2]

(Coming soon, the "?" operator.[3])

Here's an example of excessive cleverness [4]:

    fn main () {
        let number: f64 = 20.;
        // Perform a pipeline of options.
        let result = Some(number)
        .map(inverse) 
        .map(double)
        .map(inverse)
        .and_then(log) 
        .map(square)
        .and_then(sqrt);
        // Extract the result.
        match result {
            Some(x) => println!("Result was {}.", x),
            None    => println!("This failed.")
       }
    }
(It's surprising that you can use .map on a singleton. Does this actually generate collections of one element and discard them, or what?)

The designers of Go knew when to stop. The designers of Rust don't.

[1] https://web.archive.org/web/20140814230239/http://doc.rust-l...

[2] https://doc.rust-lang.org/std/option/enum.Option.html

[3] https://github.com/rust-lang/rust/issues/31436

[4] https://hoverbear.org/2014/08/12/option-monads-in-rust/

Re:The cost of forsaking C by Manishearth on Thursday October 06, 2016 @02:07AM (#12650544)
You're redefining "control flow primitive". Those are not primitives, and they affect control flow as much as functions do, aside from `?`. Closures are a concept that C doesn't have, but once you get them they obfuscate nothing. These library calls obfuscate control flow only as much as regular function calls would.

Nor are you forced to use code like the excessively clever version you talk of. People who are used to monadic programming have the choice to.

You're making the same crappy arguments like a broken record. I'm not having the same tired old discussion again.

Re:The cost of forsaking C by jhomedall on Thursday October 06, 2016 @01:29AM (#12650427)
I've only looked at Rust in passing, but looking at the documentation, that example is pretty trivial.

'.map' maps over the option. '.and_then' is the monadic bind operation, that you find in pretty much every modern programming language (frequently named 'flatMap'; even Java has this nowadays).

Re:The cost of forsaking C by S_I on Wednesday October 05, 2016 @10:19AM (#12644000)
>The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented.

Yeah, i remember using the Mac OS written in Pascal. Strangely enough, i remember it being buggy as hell and crashing pretty often (no memory protection at all).

Re:The cost of forsaking C by rpeden on Wednesday October 05, 2016 @11:15AM (#12644503)
I've read that large bits of it were written in 68k assembly too, so those parts might be responsible for the crashiness.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:48PM (#12648216)
You can't write systems programs in Pascal without escape-to-assembly. My first big 'C' project was a significant quality improvement over the Pascal it replaced, partly because of this.
Re:The cost of forsaking C by pjmlp on Thursday October 06, 2016 @03:27AM (#12650780)
Funny I managed to do that in Turbo Pascal.

Also C standard library cannot be implemented without using Assembly, unless one makes use of extensions not defined in ANSI C.

Re:The cost of forsaking C by ArkyBeagle on Thursday October 06, 2016 @07:50AM (#12651656)
You mean you managed with assembly, right? We were able to Vastly reduce the assembler footprint when using 'C'.
Re:The cost of forsaking C by pjmlp on Thursday October 06, 2016 @09:10AM (#12652104)
No I managed to do that with Turbo Pascal.

If I was talking about inline Assembly, which Turbo Pascal supported and to this day still isn't part of ANSI C, I would have said so.

The only times I actually was forced to use inline Assembly was to optimize graphics rendering and create a mouse device driver.

Both of them were a one time project.

Once upon a time I used to have some fun asking C devs for features not available in Turbo Pascal, while at the same time showing off all the safety and large project features that Turbo Pascal had and C to this day still lacks.

Back on those MS-DOS and Windows 3.x days there wasn't any feature that C compilers had and Turbo Pascal didn't had a similar feature.

Re:The cost of forsaking C by ArkyBeagle on Thursday October 06, 2016 @06:16PM (#12656583)
How would you do an INT 21 call? It's been too long; I don't remember that being possible except as either just assembler or inline assembler.
Re:The cost of forsaking C by pjmlp on Friday October 07, 2016 @02:24PM (#12662799)
With the MsDos procedure.

    program demo;
    uses Dos;
    
    var
        regs : Registers;
    
    begin
        regs.ah := $02;
        regs.dl := $07;
        MsDos (regs);  { Beep! }
    end.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:47PM (#12648204)
I'd say 1) is completely tractable, politically or not. If you're careful, "everything has a size." Only use an opaque pointer if there's... metadata that forces correct usage.

But this is up to you to enforce.

2) & 3) are pretty much covered in undergrad CS programs. If it hurts, you're doing it wrong - you don't have to dip that deeply in to OO to find excellent patterns for solving it, of you even need to go that far.

On certain platforms like the Win32 API, 2) &3) are hopeless by, it seems, design. Just do your best then :)

Re:The cost of forsaking C by chrisseaton on Wednesday October 05, 2016 @04:20PM (#12647459)
Aren't things like bounds checking (#1) an implementation detail? You could implement C with bounds checking if you wanted to. For example you say 'void* can't express size information' - well it can if you chose to implement it as a tuple of address and size. Out of bounds is already undefined, so you could make it abort with a nice error message if you wanted to. There's no need for new language features in order to do that - just change your implementation.
Re:The cost of forsaking C by xigency on Wednesday October 05, 2016 @12:30PM (#12645358)
I'm looking at writing a compiler for my own language, and I can certainly use ideas for anything that's technically feasible.
Re:The cost of forsaking C by coldtea on Wednesday October 05, 2016 @10:26AM (#12644069)
>The industry took a giant step backwards when C displaced Pascal. The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented.

The latter sentence sounds like a non sequitur.