9 ms·
Teaching D from Scratch: Is it a viable first language?
- rndm_access 5y agoI am a strong proponent of not using anything that forces you to use OOP as "baby's 1st language". Well I see OOP as a heresy in general tho. To me programming is about algorithms and data structures and data flow. Not some strange concept of OOP that does not even have an exact definition and you can see some extremists claiming that literally everything is OOP.
- 71a54xd 5y agoMy first true language was learning C in college, I'd definitely do that again. When I switched to CS everything was scheme (lisp) based which I actually preferred to Python and later on was mostly Java based. I still hate Java but it's gotten me through interview / interview screens so I'm okay with it now. For me, first language should be strict and not too loose with the rules (so not python). Once you've got the rules down and understand why they are there / why certain languages use those constructs - build from there. But take all of this with a grain of salt because I was a very distracted student more interested in working for startups during college than graduating with a nice GPA ;)
- bigodbiel 5y agoIf you want to go maverick, why not LISP?
- WalterBright 5y agoToo many parentheses.
- floatboth 5y agoCome on, that's not a real problem ;) As someone who had a Clojure phase about 9 years ago: the actual problem with modern Lisps is that they don't really offer a big set of unique good features. The basic functional map-filter-reduce "meat grinder" is everywhere (and has been almost everywhere for a long time, Java not having lambdas for ages is what clouded everyone's vision into thinking that's not the case). The other "Lisp feature" is macro metaprogramming based on homoiconicity (Code Is Data™) and we have it in some non-Lisps too now (hello Elixir) and… is it really the best way to do metaprogramming? Ehh. Well, many compiled&typed languages actually do similar-ish things: using syn in Rust proc macros / haskell-src-exts in Template Haskell you can work with code "as data". And that isn't as nice to work with as D's `static foreach/if` + reflection/introspecion thingies like allMembers/getMember.
- User23 5y agoClojure is a sort of baby’s first lisp. That’s not a bad thing by the way. Its relative simplicity and restrictiveness are usually beneficial for corporate environments and I like working in it. That said, if you want to talk about lisp you should really talk about Common Lisp. And there are a lot of solid criticisms of Common Lisp, but not enough features isn’t one I’ve heard before. The LOOP facility alone has an absurd number of features, to say nothing of the Meta Object Protocol. It’s fair to say that a proficient Lisper can write performant code in any set of paradigms you like using a modern Common Lisp implementation. That comes with some considerable trade-offs though.
- User23 5y agoI can’t tell if you’re joking, but you did make me laugh.
- chriswarbo 5y agoParentheses aren't required for Lisp, since there are many alternative representations http://chriswarbo.net/blog/2017-08-29-s_expressions.html http://chriswarbo.net/blog/2017-08-29-s_expressions.html
- WalterBright 5y ago> many alternative representations If people feel regularly compelled to redo the syntax, there's something wrong with it. "Many" means balkanization, which is another problem. (D has some carefully designed points which discourage balkanization.) It goes back to too many parentheses. So I'm only half joking about it.
- bell-cot 5y agoAh...isn't D close enough to being a superset of C that it's perfectly usable as a non-OOP language, in educational contexts?
- WalterBright 5y agoYes, it is. And you don't have to suffer under a preprocessor! (It's impractical to program in C without using the preprocessor, and the preprocessor requires use of a lot of very outdated programming practices.) D can be used in "BetterC" mode, where it operates as what C could be with modern sensibilities.
- alphaglosined 5y agoUnless you are touching something like threads or exceptions, you probably won't use classes unless it expresses your data best. So yes, perfectly usable without OOP or classes.
- nick__m 5y agofrom the article: To that end, I’ve left out a lot of the advanced features (so far), such as: Templates Type inference Operator overloading Overloading in general! __traits Classes/Interfaces/OOP Pointers/references (mostly) Memory management in general (thank you GC!)
- Jach 5y agoI have no teaching experience to back it up yet I've always felt this approach of intentionally leaving out very nifty, useful, and sometimes important bits of knowledge is bad. For sure, in the scope of one class there's not enough time to thoroughly teach everything and test on it, tradeoffs have to be made, but I'd still rather instructors explicitly mention such things as briefly as they can get away with (but three times) just with the expectation that not everyone is going to really even 'get' them and it won't be on any tests. People very much go with what they know (you'll find bubble sort in production software, alas) and if you don't even give them a sign for "here's something you might want to explore on your own or come back to if you run into it again later" most won't set foot beyond their present understanding. The worst offender in this sort of omission I think comes from the excellent SICP book -- it's not the book's fault, it's not even really trying to "teach Lisp", but people nevertheless use the book and as a side effect learn a bit of Scheme, which they confuse (because no one told them otherwise) for thinking that they now know Lisp. But they don't. In order to know Lisp one needs to learn Common Lisp with its macros, its OOP, its condition system, its types (which SBCL can check at compile time and use for more optimized assembly), its packages, its approach to interactive development... It's the same issue as high school C++ courses (I assume some of them are still around!) teaching it as C with classes, and never hearing about (let alone touching), say, templates, let alone any of the modern C++0x and on features.
- WalterBright 5y agoAlthough D supports the OOP paradigm, it does not require it at all. Very little of the D standard library uses OOP, for example.
- schaefer 5y ago"I see OOP as a heresy in general" Rndm_access, I know everyone is entitled to their opinion, but can I probe a bit on this? Can you tell us about the largest code base you feel productive in? How about the largest code base you love? How many lines of code are they? How many active developers do those code bases have (i.e. developers with weekly commits)? Do you have trouble staffing new engineers? Thanks for any reply given.
- throwawaylinux 5y agoI don't know what "heresy in general" means regarding a programming language feature, but I dislike OOP in Java and C++ code where I have encountered it. The largest code base I love and feel productive in is Linux kernel which is mostly C and assembly, medium sized project of 30 million lines, probably less than ten thousand active developers (although difficult to judge with the way development on certain features or functions can occur for years on private repositories before being merged), I would say relatively high rate of change for a project of the size.
- vgel 5y agoMy impression of the Linux kernel was that it uses a fair amount of OOP via manually-written vtables, though? For example: http://lxr.linux.no/linux+v2.6.39/include/linux/fs.h#L1569 http://lxr.linux.no/linux+v2.6.39/include/linux/fs.h#L1569
- throwawaylinux 5y agoIt frequently has structures containing objects of different types that have to identify themselves so they can be processed in different ways. This general pattern, and function pointers in C predates formal "OOP" of course, so I don't call it manually-written vtables. But yes it has this and it is a good technique. OOP languages which do this automatically for you is AFAIKS just a thin and often clunky layer of syntactic sugar on top of it.
- 5y ago
- floatboth 5y ago> claiming that literally everything is OOP Well, "is" is quite the load-bearing word in those claims. I think it is kinda true in the sense that lots of things can be represented as OOP. A great example is how Scala represents ML-style ADTs as sealed class hierarchies.
- anta40 5y agoFor beginners, Smalltalk is totally out of question, then? :D
- deleted 5y ago[deleted]
- andrewzah 5y agoTo be frank, why would one choose a language with a small community over any of the major languages? Beginners have to learn -how- to program on top of the language's syntax and toolchain itself, so it helps tremendously to be able to search online when they get stuck. And boy do they get stuck a lot, in my experience. If you pick something like python, any common beginner problem should have questions answered on stackoverflow, blog posts, etc. With a more boutique language that's not the case. Not to mention the ecosystems are much larger so chances are a library already exists to do something instead of making the beginner do it themselves and overloading them. There will be more tutorials, so people can get unstuck. More documentation around the tooling and just documentation in general exists, and so forth. --- Of course, you should teach "what you know best", but how hard is it to learn e.g. python (even just for the scope of the course) and just teach that? My favorite languages are Rust and Go, but I'm not going to foist those upon newbies just because I'm more familiar with those than javascript, python, ruby, etc. The secondary lesson here is that teaching (well) is actually quite difficult. Coming up with a curriculum is hard. Keeping students engaged and unstuck is hard. Knowing how to program doesn't prepare you for any of that.
- WalterBright 5y ago1. D is an easy language to learn. Frankly, one will probably learn better by having to explore a bit here and there rather than having every answer instantly available, no effort required. A big part of effective learning is working to solve a problem yourself. 2. D supports many styles of programming - imperative, meta, OOP, functional, machine code - so one can quickly learn these many styles without having to learn another language. With D's inline assembler, one can even use D to learn assembler without needing to deal with all the boilerplate of setting up an assembler program. 3. Interpreted languages, for example, do a good job of hiding what is actually going on. This leaves gaps in a programmer's knowledge. 4. D has a active and large learn forum. Help is available as needed. 5. Being a D programmer marks one as innovative and willing to try new things. Many employers consider D experience on the resume as a nice plus. 6. D includes a C compiler (ImportC) so if you must use a solution in C, it's easy to access.
- 5y ago
- gavinray 5y ago> "The features that I found the kids handled well were basic types like ints and strings (though what a funny name “string” is, that took a while to sink in)" I have so ingrained in my brain the association of "string" to a text variable type that I didn't even consider the fact the name is bizarre. It really doesn't make sense at first sight, and this is something I probably would not have realized until someone asked me "Why do they call it a 'string'?" Fun read. D rocks.
- doovd 5y agoWell, if you learn about chars and then realise a string is a "string" of chars, then it's not so bizarre. If we're starting with ints before introducing floats, then why not start with chars before introducing strings.
- girvo 5y agoWe only apply that to strings though. float[] isn't a string of floats. And lots of languages have strings that aren't arrays of chars too, so I don't really think that's it either. Where does string come from. How odd.
- housecarpenter 5y agoYou do still hear people speaking of a string of bits, as well as a string of characters. I think the word "array" tends to be preferred for lists of numbers, since in its original sense in mathematics it was (and is) a synonym for "matrix". For lists of arbitrary objects I guess "array" won out by random chance, more or less.
- girvo 5y agoReally? Fascinating. I’ve not heard anyone call them that in my 20+ years of programming!
- nicoburns 5y agoWell, not all languages have chars. And even in those that do, strings are not always made up of them (e.g. in Rust, char is 32 bits and strings are utf8).
- gavinray 5y agoRE: Debugging D in VS Code, this hasn't been my experience at all > "Another challenge I’ve faced is the lack of a good debugging experience for VS Code on Windows. The C debugger for VS Code displays, for example, a string as a length and a C string (which might have trailing garbage). I’d rather not confuse them with this. I have read that Visual D has a better debugging experience, but I need dub support for these projects, and Visual D focuses on Visual Studio integration, something I don’t necessarily want to deal with in teaching these kids. " You need to use the Microsoft C/C++ "cppvsdbg" option in your "launch.json" config as the "type", and also to use Webfreak's custom Natvis file for how to display D native types in the debugger: https://code.visualstudio.com/docs/cpp/launch-json-reference#_showdisplaystring https://code.visualstudio.com/docs/cpp/launch-json-reference... https://github.com/Pure-D/dlang-debug#natvis-with-vsdbg https://github.com/Pure-D/dlang-debug#natvis-with-vsdbg This makes associative arrays display properly, and strings, etc. I think this has been integrated in latest code-d. You want to compile with "-gc" flag though (not sure if this is the same flag name on DMD as it is on GDC/LDC). The LLDB debugging is worse than the "cppvsdbg" mode IME.
- Jansen312 5y agoDepend on what is your target audience. If they are beginner comp sci students then D is ok. Preferably something lispy like Racket. If they are more of "learn to code" and get high paying job, D is not recommended. Python, Java/Kotlin, R, C# or C/C++ would be better choices. If you are focusing on embedded students, C is a must and maybe Rust. If you are focusing on web development, then Javascript/Node is a must. Some people would argue that learning any languages is ok as you learn the concept. But this argument is the same as learning Japanese or Korean so you have "upper hand understanding" of Chinese. Why not just go straight learn Chinese than beating around the bush learning something "similar". There are concepts in C/C++ that are hard to replicate in C# or Python such as pointers and low level memory management. Or, data science community on Python platform that are scarce in others. Same with r for statistics, C# for .Net/Microsoft, Java/Kotlin for Android stuff. Most people have limited ability to learn 1 or 2 languages over their lifetime. Just focus on that most useful and accessible. Good one will always go on and create their own languages.
- WalterBright 5y agoD experts get very well paid programming jobs.
- nerdponx 5y agoI'm sure that Common Lisp experts do, too. But how many of those jobs are there really? Also: are they well-paid because they are D experts, or is being a D expert merely correlated with other traits that explain their high pay?
- WalterBright 5y ago> But how many of those jobs are there really? All I can say is they haven't had any trouble getting those jobs. > are they well-paid because they are D experts, or is being a D expert merely correlated with other traits that explain their high pay? Both. As related to me by their employers. D experience looks good on the resume. It strongly suggests that the person is not one of those do as little as possible people - that they actually like programming.
- teleforce 5y agoPlease check the previous discussions on HN regarding seven deadly sins and seven desirable traits of introductory language design [1]. Not sure whether Walter read the paper before designing D because the reference paper is written before D was started, but interestingly D avoids most of the sins and does follow the recommendations. The paper, however, did not mention not having GC as one of the deadly sins but most of modern languages specifically designed for new learners namely ABC and Scratch have GC. The fact that D has GC by default make it very suitable for new introductory programming language (see the 7th recommendation for choosing the suitable level of abstraction). [1]Seven Deadly Sins of Introductory Programming Language Design (1996) [pdf]: https://news.ycombinator.com/item?id=28859449 https://news.ycombinator.com/item?id=28859449
- WalterBright 5y agoI have not seen that paper before, thanks for the link!