Earlier quoted context omitted.
What's wrong with ternary?
Nothing but when you nest them a whole bunch they are far harder to read and understand that if/else.
SICP in JavaScript
61–70 of 126 posts
Re: SICP in JavaScript
#62Earlier quoted context omitted.
I frankly find it hard to imagine an expression form of if...else that's more readable than either the JS or Scheme versions of the code. In fact, I believe the problem with the JS example's readability is the formatting. Here's how I'd format the same code, and I find this quite readable: function deriv(exp, variable) { return is_number(exp) ? 0 : is_variable(exp) ? is_same_variable(exp, variable) ? 1 : 0 : is_sum(e…
The 0 and 1 are completely unnecessary though in some of these. Example is_same_variable(exp, variable) ? 1 : 0 If is_same_variable returns a truthy value then return 1 else 0. We can remove that and it will still follow the same while also being more readable
Re: SICP in JavaScript
#63On my phone I just get a drawing of an alien spaceship? I tried loading it through an archive (and I do get the front page of a web book) but none of the links work there.
it's supposed to redirect to https://sourceacademy.org/sicpjs/index
Re: SICP in JavaScript
#64Earlier quoted context omitted.
I see this opinion voiced all the time, and I can never understand how people can struggle with something like nested ternaries. Surely a straightforward use (i.e. not a weird edge case) of very basic syntax shared by most widely used programming languages shouldn't cause much of an issue? It should also be easier to reason about nested ternaries than an equivalent set of nested if-elses, because at least with ternar…
Should ternaries be left or right associative?
Re: SICP in JavaScript
#65What I loved most about my class based on SICP was that I learned a whole new way to reason about code, and that came from using Scheme. They changed the intro class at Berkeley to use Python a while back, when the folks who knew lisp/scheme retired, and I think it made the class much worse. This is really the death knell of SICP isn't it?
Re: SICP in JavaScript
#66Re: SICP in JavaScript
#67Re: SICP in JavaScript
#68I started this book with coworkers and it fell really flat. I haven't read the original, but knowing Scheme I could see why the book would be structured the way it is. In JavaScript, though, it really just doesn't work. The code is horribly non-idiomatic for JS, and because JS isn't actually Scheme the order of the concepts introduced doesn't make sense. When it does talk about JavaScript, it's condescending towards…
Anyone with strong opinions about mainstream programming languages is automatically suspicious to me.
I mean, I get it - plenty more elegant and better thought-out languages than JavaScript, with their practitioners pounding the floor, saying "it should have been me - not him!".
But, ultimately, who can't write good code just because they're not using their favourite language?
Re: SICP in JavaScript
#69Earlier quoted context omitted.
I think the Scheme version of SICP will live on outside of academia and CS undergrad studies. I'm using SICP for self-learning and I had the choice of Scheme, JS, or Python. I still chose Scheme. This is because I figured Scheme would offer something those other languages didn't since Scheme is the original language of the book and Scheme is just "different" than other languages. It forces you to think differently ab…
What's deterring me from pulling the trigger on the Scheme version is the price. CAD$87 seems a bit steep for a paperback edition that's almost 30 years old. The JavaScript version is CAD$20 cheaper.
Used books are awesome. I have north of 500 books and I doubt more than 50 were purchased new. Only that many because some of my relatives want Christmas and birthday wishlists every year, but won't shop anywhere but Amazon and think it's weird to buy someone a used book as a gift (I'd rather have 2-3x as many books for the same money, but hey, I'm not the one paying, so whatever, I guess).