Live data from Hacker News

Learn Programming with OCaml

usr.lmf.cnrs.fr

131–140 of 150 posts

Re: Learn Programming with OCaml

#131
post #116

Earlier quoted context omitted.

I do not think that pre- and postincrement operator being inspired by PDP-11 has anything to with fundamental system design questions.

> Q. How do you port an OS from one language to a new one, pre-LLM? A. you reduce impedance mismatch, but making the new language using similar concepts and mechanisms -- You're right, this table is just a coincidence, probably derived from the standard math notation, and used in many PLs like FORTRAN and Python ;) PDP-11 C INC R ++i DEC R --i ADD src, dst dst += src SUB src, dst dst -= src (R)+ *p++ -(R) *--p X(R) p…

You are being somewhat disingenuous with your comment ;-)

PDP-11 was hugely influential in the later designs of various Hardware, Software, OS, Languages etc. See for example; Dave Cheney's What Have We Learned from the PDP-11? - https://dave.cheney.net/2017/12/04/what-have-we-learned-from... The conclusion from the article;

While its development was sometimes chaotic, and not without its flaws, the PDP-11 is at the intersection of many threads of history.

Hardware, software, programming languages, operating systems, have all been influenced by the PDP-11. I wager there is not a single person in this room who cannot trace the lineage of the language they work with, the computer they use, or the operating system it runs, back to the PDP-11.

And that is worth celebrating.

While the PDP-11 instruction set was certainly influential in the design of the "C Abstract Machine" the latter was generalized to accommodate other architectures extent at that time (eg. Honeywell 6000, IBM System/370) with enough flexibility that you can implement a C compiler for almost any architecture you can think of. That is its strength.

David Chisnall's criticisms in his C Is Not a Low-level Language: Your computer is not a fast PDP-11 (https://queue.acm.org/doi/10.1145/3212477.3212479) has to do mainly with the fact that the abstract machine was serial execution with no concept of memory protection/models. But this very flexibility is what makes C easily portable to dinky little MCUs which do not have those features while allowing the programmer to explicitly program those using libraries on more complex processors with lots of parallel cores, mmus etc.

Thus a single thread runs on a "C abstract machine" on a core (i.e. the bare minimum) and it is up to the programmer to manage interactions between the threads on various cores. We have lost nothing but perhaps burdening the programmer with more knowledge of hardware complexity which was an acceptable tradeoff then. Note also that there already exists various extensions to C to handle parallel programming directly eg. "Concurrent C" by Narain Gehani et al. The industry however chose to settle on external libraries and optional thread support in C11 again keeping with its minimality and flexibility mantras.

Re: Learn Programming with OCaml

#132

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

> I believe that an ML should be the First Language for Computer Scientists.

I'm not sure how much influence a First Language has - the biggest impact might be whether someone decides to continue learning to program. I'd also worry that we might lose something if all computer scientists are too similar. There are lisp believers, and there are those who swear by C; and I think the field of CS would be less rich if either were missing. Given that, it's a good thing that there are a variety of languages taught as first languages, and I'd like to see the variety widen (I don't know of any CS degree which begins by teaching Forth).

Re: Learn Programming with OCaml

#133

This book is a great. A common misunderstanding around OCaml is to classify it as a functional programming language, it is actually a multi-paradigm language. In short, in OCaml, you can write in any paradigm you want, imperative, object, or functional. Typically, I write in a mix of OCaml and stubs in C (for bindings to Linux libraries), for everything, to replace shell scripts, Python scripts, Javascript/Typescript…

A good comment to motivate myself to learn the language; particularly the last line ;-)

I personally detest the babel of languages involved in "modern ways of programming" and have settled on C/C++ for everything since they are available everywhere. The only other languages i am willing to seriously consider adding to my repertoire are Erlang (functional/concurrent/distributed/fault-tolerant/hot-reload) and Prolog (knowledge representation and derivation using predicate logic) along with a formal verification language like Lean4/TLA+ etc. due to LLMs usage.

Re: Learn Programming with OCaml

#134

Earlier quoted context omitted.

> Q. How do you port an OS from one language to a new one, pre-LLM? A. you reduce impedance mismatch, but making the new language using similar concepts and mechanisms -- You're right, this table is just a coincidence, probably derived from the standard math notation, and used in many PLs like FORTRAN and Python ;) PDP-11 C INC R ++i DEC R --i ADD src, dst dst += src SUB src, dst dst -= src (R)+ *p++ -(R) *--p X(R) p…

You are being somewhat disingenuous with your comment ;-) PDP-11 was hugely influential in the later designs of various Hardware, Software, OS, Languages etc. See for example; Dave Cheney's What Have We Learned from the PDP-11? - https://dave.cheney.net/2017/12/04/what-have-we-learned-from... The conclusion from the article; While its development was sometimes chaotic, and not without its flaws, the PDP-11 is at the…

Note that IMHO there are quite a few things incorrect or misleading in this article.

Re: Learn Programming with OCaml

#135

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

> I believe that an ML should be the First Language for Computer Scientists. I'm not sure how much influence a First Language has - the biggest impact might be whether someone decides to continue learning to program. I'd also worry that we might lose something if all computer scientists are too similar. There are lisp believers, and there are those who swear by C; and I think the field of CS would be less rich if eit…

The best programming course I had in college was one on comparative programming languages (and not just 'cause I was the only student who was able to do all of the Lisp exercises solo) --- it was quite striking getting an overview of the history of computer science and to see the myriad approaches which had been used.

Re: Learn Programming with OCaml

#136
post #134

Earlier quoted context omitted.

You are being somewhat disingenuous with your comment ;-) PDP-11 was hugely influential in the later designs of various Hardware, Software, OS, Languages etc. See for example; Dave Cheney's What Have We Learned from the PDP-11? - https://dave.cheney.net/2017/12/04/what-have-we-learned-from... The conclusion from the article; While its development was sometimes chaotic, and not without its flaws, the PDP-11 is at the…

Note that IMHO there are quite a few things incorrect or misleading in this article.

Do you mean in Cheney's article or Chisnall's article or in my comment?

Re: Learn Programming with OCaml

#137
post #122

Earlier quoted context omitted.

C doesn't provide anything that C++, D, Object Pascal, Ada, Modula-2, Zig, Swift and many others won't do as well.

All great options as well, with the caveat that it’s possible to “ignore” the parts that make C useful as a teaching tool. Most modern languages have ways to automate parts of memory management, and rightfully so. But you should at least be somewhat aware of what is going on under the hood.

Some of the suggested languages are as old as C, with better ergonomics if you mean ignorig is doing string concatenation instead of manually handling char buffers with pointer arithmetic, or proper reference parameters instead of being forced to pass the address of output variables manually, which is nonetheless possible in the suggested languages.

What low level thing do you think C can do, but Modula-2, Ada or Object Pascal are unable to provide the comparable feature?

Also taking into account possible C extensions not covered by ISO.

Re: Learn Programming with OCaml

#138
post #123

Earlier quoted context omitted.

If the compiler optimizer doesn't reorder the struct fields depending on which flags or pragmas are used, and you could teach that as well in other compiled languages, ignoring the market size of each language.

The C optimizer is not allowed to re-order, so, unless you've specifically used some implementation override you know exactly how C will lay out basic types. Likewise packing isn't allowed by the standard, so you'd again only need to talk about packing if you want to. This seems like a reasonable place to start. Like the way driving school teaches you a U-turn but not a J-turn. Is a J turn actually a thing you might…

Well, we cannot talk about ISO C for some things, and Compiler Specific C for others, depending on the convinience of what is being discussed.

Re: Learn Programming with OCaml

#139

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

An ML is great for the theory or abstraction side of programming, but C is also hands down the best language to get a sense of how the computer is running your program. It’s still an abstraction, but at least being aware of memory management, copying vs referencing, etc are hugely important concepts that ML languages can hide.

Maybe we were led into a false dichotomy by the title. If someone wants to learn programming for other reasons than as a mean to a goal - which will become more and more rare because LLMs do that already - this person must not learn just one language but one per major paradigm : C (imperative/procedural), Smalltalk (OOP), Prolog (logic), SQL (declarative, although maybe there are better representatives), OCaml (functional, although one can go for Haskell or Lisp/Scheme), and Forth (concatenative, but also to take a look under the hood of interpreters/compilers/VMs).

Re: Learn Programming with OCaml

#140

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

An ML is great for the theory or abstraction side of programming, but C is also hands down the best language to get a sense of how the computer is running your program. It’s still an abstraction, but at least being aware of memory management, copying vs referencing, etc are hugely important concepts that ML languages can hide.

[deleted]
Post reply on HN