Hacker News new | ask | show | jobs
by willvarfar 495 days ago
Whereas if K&R had adopted Pascal (and tweaked the language to support whatever limitations they ran into when making the OS) instead of inventing C to make Unix, your experience would have been flipped; should C++ have come along, it would be the one with the header translation costs etc?

Wirth went on to create Modula2 and Oberon and make operating systems in them. It is fun to imagine a world where that was the way chosen forward instead of C to C++.

1 comments

I believe C is closer to what happens in the computer, than the Pascal is. I am not advocating for C as I dreadfully fear of this language (though I have experience in it, it always fills me with respect when I'm getting to close). What I'm saying is that for example, LPS String implementation in Pascal is Pascal-specific, not ubiquitous in systems, and handling PChar in Pascal gives a headache. Simple task: call a Windows function with your own string from Pascal. (Maybe my experience is too old and I don't know that this has been solved already, but back when I tried it, it was a nightmare)
FWIW that string bit has been solved since Delphi 2 introduced "huge strings", which are basically reference counted, copy-on-write null terminated strings. A variable of type "string" or "ansistring" (the former is an alias for the latter when huge strings are enabled, which are by default in Delphi 2 projects) is actually a pointer to the first character of the null terminated string, making it memory compatible with C calls (the "header" that contains reference count, etc is placed at a negative offset from the pointer).

With modern Delphi and Free Pascal (another object pascal dialect) you rarely have to worry about the differences between ansistrings and C strings.

(the name "ansistring" is kinda odd but blame Borland for that - though the odd name most likely helped avoid conflicts with existing Turbo Pascal and Delphi 1 code)

That said, i wouldn't call modern Pascal a simple language at all. Free Pascal for example has three different object oriented types that are all incompatible with each other and none cover all usage scenarios - and hidden "gotcha"s exist in the language ever since the early Delphi days like the implicit "Result" variable in functions treated as a "var" (passed by reference) parameter, meaning that a call like "Foo:=Bar" where "Foo" is a variable and "Bar" is a function and you'd expect "Bar" to be called and its result assigned to "Foo" actually has "Result" inside "Bar" be whatever "Foo" was because the statement is basically as if "Bar" had a single argument where "Foo" was passed by reference.

If we move beyond the original ISO Pascal from 1976, there is hardly any ISO C feature that isn't available in dialects like Object Pascal.

Even in C you cannot just give a char * to an Windows function, unless you are stuck using ANSI version of the APIs.