Live data from Hacker News

Learn Programming with OCaml

usr.lmf.cnrs.fr

121–130 of 150 posts

Re: Learn Programming with OCaml

#121
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…

I do not disagree with the point that some superficial aspects are inspired by the PDP-11, I disagree with that this has anything to do with the fundamentals of computing architecture.

It would also completely contradict the whole idea that everything today simulates the PDP-11 design because of C, as few architectures have this auto-in/decrement addressing modes despite C having native syntax.

Re: Learn Programming with OCaml

#122

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.

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

Re: Learn Programming with OCaml

#123
post #115

Earlier quoted context omitted.

> an imperative language procedural language with a clean mapping to ASM C really isn't as great for this as is often suggested either, not for decades at least K&R's original compiler on an actual Digital machine from that era makes the case best, but remember this is the era when if you hot loop over modifying a variable your compiler is going to emit memory stores for each iteration - because that's what you wrote…

> C really isn't as great for this as is often suggested either, not for decades at least It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for). We (University o…

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.

Re: Learn Programming with OCaml

#124
post #115

Earlier quoted context omitted.

> an imperative language procedural language with a clean mapping to ASM C really isn't as great for this as is often suggested either, not for decades at least K&R's original compiler on an actual Digital machine from that era makes the case best, but remember this is the era when if you hot loop over modifying a variable your compiler is going to emit memory stores for each iteration - because that's what you wrote…

> C really isn't as great for this as is often suggested either, not for decades at least It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for). We (University o…

The layout rules for C struct are definitely a blessing for teaching I can see that.

Re: Learn Programming with OCaml

#125
post #123
post #115

Earlier quoted context omitted.

> C really isn't as great for this as is often suggested either, not for decades at least It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for). We (University o…

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 need? Maybe, but it's definitely not where we should start.

Re: Learn Programming with OCaml

#126
post #122

Earlier quoted context omitted.

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.

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.

Re: Learn Programming with OCaml

#127

Earlier quoted context omitted.

> It’s still an abstraction C is still heavily abstracted. Modern OS evolved in conjunction with C s.t. it behaves like a C runtime simulating a PDP11 (I remember reading a nice article on that). To learn system, what you need is an OS course, not C. I'd say the current C-based stack is in a quite embarrassing state.

For someone just starting to learn CS, it should not matter whether they're on PDP-11 or x64 or ARM. You can't start teaching with pipelining and speculative branch execution. So C is good choice because there is a simple CPU architecture that it maps to well.

Fully agree. C sits in an almost perfect level of abstraction for students to get a vague sense of how the computer runs code.

Those that don’t need low level details can spend their professional career in languages like python and JavaScript while still have a sense of what lies beneath the abstraction.

For those that do want or need to go deeper, C is an excellent jumping off point into ASM and arch specifics.

Re: Learn Programming with OCaml

#128

Earlier quoted context omitted.

For someone just starting to learn CS, it should not matter whether they're on PDP-11 or x64 or ARM. You can't start teaching with pipelining and speculative branch execution. So C is good choice because there is a simple CPU architecture that it maps to well.

Fully agree. C sits in an almost perfect level of abstraction for students to get a vague sense of how the computer runs code. Those that don’t need low level details can spend their professional career in languages like python and JavaScript while still have a sense of what lies beneath the abstraction. For those that do want or need to go deeper, C is an excellent jumping off point into ASM and arch specifics.

C hasn't presented an accurate model of how computers actually work for decades. It's a high level language LARPing as a low level language.

Re: Learn Programming with OCaml

#129

Earlier quoted context omitted.

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 learn Rust as a middle ground between ML and C, then? It has sum types like ML and teaches you memory management like C.

The allure of Rust is that you don’t have to manually manage memory.

Lifetimes are a compiler safety abstraction and mostly unrelated with how the computer runs your program.

Learning a language like C helps to understand why lifetime annotations are needed and how the compiler uses them.

Re: Learn Programming with OCaml

#130

Earlier quoted context omitted.

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.

> but C is also hands down the best language to get a sense of how the computer is running your program. C is in an odd position right now to argue it is how the machine is really working. Computers are more complicated since bigger caches entered the picture. Hell I do not think even ASM is a good approximation on how machine really work given the data dependencies will make stuff being processed in parallel instead…

> C is in an odd position right now to argue it is how the machine is really working

This is exactly what makes it great for teaching. Students don’t need to know actual arch or hardware details. They just need to grasp the core concepts of what is happening on the hardware.

For that purpose the ideal teaching language is lower level than python, javascript, Ocaml, etc without diving into nitty gritty arch specifics.

C is the undisputed champion in that domain.

Post reply on HN