Live data from Hacker News

SICP in Python

wizardforcel.gitbooks.io

111–120 of 136 posts

Re: SICP in Python

#111
post #60
post #50

If you wanted to delve into the original 1984 LISP/Scheme version by Abelson and Sussman, I recommend you take a look at https://opendocs.github.io/sicp/sicp.pdf which is based on the MITPress HTML version, released under a permissive CC-by-SA license. https://mitpress.mit.edu/sites/default/files/sicp/index.html (nb. The pdf starts out with a curious little 'texinfo foreword'. Being able to type `info sicp` in one's…

> The pdf starts out with a curious little 'texinfo foreword'. Being able to type `info sicp` in one's shell? Yes, mostly in Emacs, but you could also do it in your shell. :) https://www.neilvandyke.org/sicp-texi/ The Texinfo format happened a couple years ago, in the early days of the Web, and let people on modest computers who couldn't run a Web browser work through SICP on their screens (no need for expense of pri…

[Late reply -- forgot to hit the button. ;]

Thank you for the pointer and, more so, your contributions.

That screenshot of SICP in Emacs -- running side-by-side with the built-in Guile interpreter -- induces peculiar sensations. An echo of how things could've been and possibly still are in some obscure(d) corners of the Net. An interactive learning environment that at least points in the right direction. It certainly looks elegant and somewhat inspirational to me (though my inner Alan Kay is voicing some profound objections ;).

In any case: you carried that torch for a while, don't be hesitant accepting apparently undue credit -- there's too little, in any case, to warrant worry. ;)

Re: SICP in Python

#112

Earlier quoted context omitted.

It is different from how Ruby and Javascript handle default arguments. I'm surprised Python does that, since I would expect function arguments to be reset to their defaults each call. That's a major side effect.

It's pretty odd behavior, yeah. It's easy to work around (set the default to None and then set the actual default in the function body), but I don't know if I've _ever_ seen anyone want it to behave as it does now.

It does make sense to evaluate the default value for the parameter at the point of definition for serveral reasons. First of all, the default value does not have to be a literal value, and if you wanted it to be evaluated at call time the function would need to capture all of the default values in a closure.

  default = 10
  def foo(x=default):
      return x
  default = 20
  assert foo() == 10
I think tat makes a lot of sense.

It could also be that the default value is a more ocmplex expression, we could use a function to generate a default argument.

  def foo(x=create_default(y, z))
By evaluating it at definition time we only have to evaluate the expression once and not have this weird lazy expression.

And yes it is used, for example the fastapi Dependency Injection system has been build quite cleverly using the ability to construct default values

https://fastapi.tiangolo.com/tutorial/query-params-str-valid...

Yes it is one of those things you just have to learn, but there are tons of stuff like that in most programming languages.

Re: SICP in Python

#113
post #25

It made me so sad when I found out CS61A was being taught in Python. I love Python, but I also know that I would have missed out on so much wonderful information if I hadn't learned Scheme. It was truly mind blowing when they had us implement a Scheme interpreter in Scheme, and then add infix operators. I think the original SICP was perfect for an intro course. It was also the great leveler, because even if you enter…

It just isn’t the same, Scheme was such a wonderful educational language.

Re: SICP in Python

#114
post #92

I don't want to sound snarky, but... is this really it? I haven't looked through SICP itself, and have no formal CS background, but it always seemed like SICP was treated like a forbidding rite of passage. The Python version, if it's faithful to the original, seems pretty lightweight.

One of the non-obvious things about SICP is that there is a lot of really good stuff in the footnotes and the exercises. You aren't doing yourself any favors if you skim over either of them.

Indeed, a download and quick look shows that the book has a lot more content than just a sequence of lessons. I've immersed in the foreword, and enjoying it greatly. The best textbooks are not just informative, but written to be enjoyed as literature.

Re: SICP in Python

#115
post #92

I don't want to sound snarky, but... is this really it? I haven't looked through SICP itself, and have no formal CS background, but it always seemed like SICP was treated like a forbidding rite of passage. The Python version, if it's faithful to the original, seems pretty lightweight.

One of the non-obvious things about SICP is that there is a lot of really good stuff in the footnotes and the exercises. You aren't doing yourself any favors if you skim over either of them.

[deleted]

Re: SICP in Python

#116
post #92

Earlier quoted context omitted.

One of the non-obvious things about SICP is that there is a lot of really good stuff in the footnotes and the exercises. You aren't doing yourself any favors if you skim over either of them.

Indeed, a download and quick look shows that the book has a lot more content than just a sequence of lessons. I've immersed in the foreword, and enjoying it greatly. The best textbooks are not just informative, but written to be enjoyed as literature.

It's a classic for that reason. Enjoy!

Re: SICP in Python

#117
post #8

Earlier quoted context omitted.

in the software world, one can avoid the monster that is c++ rather successfully, but it's gotten to the point that no matter what, python is thrust upon you to deal with. "hey here's this thing that is barely working" (in large part because it's written in python) "and we'd like you to maintain it but not switch from python" (because anything besides python makes us uncomfortable). meanwhile, python makes me uncomfo…

I see we've reached the point in python's popularity where it is cool to hate it. Happened with C++, Java, Javascript, PHP, and now... Python, of all things. Maybe the least bad of all of those. Like it or not it's here to stay. If Scheme (or whatever language you use) was as popular as python you would think it is bad too since most code out there would be made by amateurs, and its flaws (which all languages have) w…

> I see we've reached the point in python's popularity where it is cool to hate it. Happened with C++, Java, Javascript, PHP, and now... Python, of all things. Maybe the least bad of all of those.

first of all, this is a non-argument and has nothing to do with what i said. i don't hate python because it's cool. i hate python because i am concerned with building robust and reliable software and python makes that difficult. period. i am wholly unconcerned with what's cool or not and am concerned with developing software that can be relied on, maintained, and extended to help save money, save lives, save time, and makes the technology get out of the way.

those languages you listed are not a useful comparison. they're also terrible.

> Like it or not it's here to stay.

maybe true, but it doesn't mean i should just sit back and accept writing bad code.

> If Scheme (or whatever language you use) was as popular as python you would think it is bad too since most code out there would be made by amateurs, and its flaws (which all languages have) would be unavoidable.

it is true that bad code is bad code, and code written by people who don't take it seriously will not be magically good no matter what language they use. however, some languages make it easier if you do take it seriously. i take it seriously and python fights me.

Re: SICP in Python

#118
post #28
post #8

Earlier quoted context omitted.

in the software world, one can avoid the monster that is c++ rather successfully, but it's gotten to the point that no matter what, python is thrust upon you to deal with. "hey here's this thing that is barely working" (in large part because it's written in python) "and we'd like you to maintain it but not switch from python" (because anything besides python makes us uncomfortable). meanwhile, python makes me uncomfo…

As a Python programmer, it would be interesting to hear why you thing Python in unprincipled? I haven't felt that myself so curious to see what your thoughts are.

here's my other comment that talks about this: https://news.ycombinator.com/item?id=23008968

even among dynamically typed languages, python is terrible. it has no real way to build up new types in a principled way, and you have to result to using (and abusing) the class system, which is hack after hack.

python also ignored and continued to ignore things that already existed in languages and advances. it also doesn't really like using data-type driven development. go ahead and search for "python records". you'll get nothing, and the best reference is a blog post (https://dbader.org/blog/records-structs-and-data-transfer-ob...) that leads you to a wide variety of solutions, all inconsistent with each other and not conventionally used. now search google and literally the top result for each query is the following:

"f# records" (https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...)

"elixir records" (https://hexdocs.pm/elixir/Record.html)

"clojure records" (https://clojuredocs.org/clojure.core/defrecord)

"racket lang records" (https://docs.racket-lang.org/rebellion/Records.html)

another area that python doesn't take seriously is scoping. the scoping rules and exceptions are complex, and this makes the language very dangerous. i mentioned one in the other comment i linked. python has weird scoping stuff with lambdas. python even has a keyword that makes a locally bound variable available in the calling scope (https://docs.python.org/3/reference/simple_stmts.html#nonloc...). no thank you. this is absolutely terrible design, and yes, i have seen it in production code (not written by me). just search "python scoping" or "python nonlocal", and you'll come across people confused by a plethora of edge cases.

python is just complicated. it has no simple core. it is a huge lump of stuff. both f# and racket are definitely more complicated than python in that they have behavior and features far exceeding python. however, they are principled. in one way, they have very simple core languages such that if you ignore all the fancy stuff, you can still write beautiful, reliable code with the simply designed core language. as you move to the more complicated stuff, you utilized this simple core over and over to build software that is still understandable. it allows you to build predictable software.

another area of principles i look for in a language are why it was created and what are the motivations of its creator(s). f# was created to bring a functional language to .net to utilize .net's vast functionality and test .net's language making and support capability. the development originally started with haskell but transitioned to ocaml since the model matched better with .net. don syme is a very practical language designer and an actual computer scientist. here is a draft of a paper by him about the history of f# (https://fsharp.org/history/hopl-final/hopl-fsharp.pdf). it's a useful read. racket was created to extend scheme into a new language that fully adopted language-oriented programming (lop) and had supporting libraries for normal development. this means taking an extremely principled language and extending it to support a new paradigm of software development in a principled, controlled way. see the paper a programmable programming language (https://cacm.acm.org/magazines/2018/3/225475-a-programmable-...). the authors of racket are also computer scientists and care about robust software development. python was created by someone interested in esoteric languages (ABC) and in creating a systems scripting language as a hobby project. the creator resisted and continued to resist many already existing language designs and features (found in scheme and ML-dialects such as SML). for example, lambda, map, filter, and reduce only exist in python because he begrudgingly accepted patches that someone else did. another example of unprincipled-ness is the creator's seemingly proud declaration to use multi-line string literals as multi-line comments since python did not have and still does not have multi-line comment support (https://twitter.com/gvanrossum/status/112670605505077248).

these things alone make me wholly not interested in python. i want to use a language that was created for a reason and in a principled way that solves a problem that i am facing. i also feel i need to agree with the reasons and also the philosophy of the language designers. none of this exists for me in python.

the early history of f# (https://fsharp.org/history/hopl-final/hopl-fsharp.pdf)

a programmable programming language (https://cacm.acm.org/magazines/2018/3/225475-a-programmable-...)

Re: SICP in Python

#119
post #74

Earlier quoted context omitted.

This relates heavily to the "what language should be taught in schools" argument. I usually answer "Java". And it's not even that I particularly like Java, it's just that the discussion often neglects that the course involved is all about classes, getters and setters, inheritance and so on. It's nonsense to shoehorn this into many other languages.

But why is the course “all about classes, getters and setters, inheritance and so on”? It sounds like a Java class before the language is even chosen. No wonder the best choice ends up being Java. When I took CS in school, these were not the central themes. On the last day of class the teacher showed us a short program in this funky new language called “Java” and we all had a good laugh at how it tried to make everyt…

I think it really depends on if you're teaching CS or programming. If I was designing a CS curriculum I would almost certainly start with something like Haskell, Lisp or Scheme. If I was designing a programming curriculum I would almost certainly start with Java, C# or Python.

At the end of the day your average programming job at your average company is “all about classes, getters and setters, inheritance and so on”, and if you want to prepare students for that, you should probably focus on that.

Re: SICP in Python

#120
post #48
post #39

Earlier quoted context omitted.

In line with this, list comprehensions are one area of python I find particularly clunky. They work fairly well for a single map or filter operation, alright for both mapping and filtering, and are absolutely unreadable for anything more complicated. A big part of this in my opinion is how they scramble the flow. Instead of taking a piece of data and performing successive operations on it, both in logic and in syntax…

map(lambda x:x^2, filter(lambda x:x%6==0, map(lambda x: x*2, getNumbers()))) Would probably be a more pythonic way to do that, avoiding list comprehensions. Easier to read with added lines and indentation. But tbf I do appreciate the ability to chain operations in JS without subclassing objects like list.

Funny how 'pythonic' can mean different things to different people. I've been developing in python on and off for the best part of a decade, and in my world comprehensions are considered far more 'pythonic' than map/filter/lambda.
Post reply on HN