| ▲ | gignico 2 hours ago | ||||||||||||||||||||||
I’m just going to start teaching classes of C programming to university first-year CS students. Would you teach `defer` straight away to manage allocated memory? | |||||||||||||||||||||||
| ▲ | leni536 2 hours ago | parent | next [-] | ||||||||||||||||||||||
It's still only in a TS, not in ISO C, if that matters. | |||||||||||||||||||||||
| ▲ | flohofwoe an hour ago | parent | prev | next [-] | ||||||||||||||||||||||
No, but also skip malloc/free until late in the year, and when it comes to heap allocation then don't use example code which allocates and frees single structs, instead introduce concepts like arena allocators to bundle many items with the same max lifetime, pool allocators with generation-counted slots and other memory managements strategies. | |||||||||||||||||||||||
| ▲ | zffr an hour ago | parent | prev | next [-] | ||||||||||||||||||||||
My suggestion is no - first have them do it the hard way. This will help them build the skills to do manual memory management where defer is not available. Once they do learn about defer they will come to appreciate it much more. | |||||||||||||||||||||||
| ▲ | orlp an hour ago | parent | prev | next [-] | ||||||||||||||||||||||
In university? No, absolutely not straight away. The point of a CS degree is to know the fundamentals of computing, not the latest best practices in programming that abstract the fundamentals. | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | kibwen an hour ago | parent | prev | next [-] | ||||||||||||||||||||||
If you're teaching them to write an assembler, then it may be worth teaching them C, as a fairly basic language with a straightforward/naive mapping to assembly. But for basically any other context in which you'd be teaching first-year CS students a language, C is not an ideal language to learn as a beginner. Teaching C to first-year CS students just for the heck of it is like teaching medieval alchemy to first-year chemistry students. | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | uecker an hour ago | parent | prev [-] | ||||||||||||||||||||||
IMHO, it is in the best interest of your students to teach them standard C first. | |||||||||||||||||||||||
| |||||||||||||||||||||||