by latenightcoding · 4y ago · 0 comments
(import os)
(import [os.path :as op])
(with [f (open (op.join dir_name file_name) "w")]
(.write f "..."))
Some things you just have to learn, like using `(setv var value)` to do assignment, or the fact that `(for)` is an imperative loop while `(lfor)` is a list comprehension, but a little experimentation goes a long way and the docs are quite good.`pip3 install --user hy`
as mentioned in the first page of the docs:
a link: https://fable.io/blog/2022/2022-06-06-Snake_Island_alpha.htm...
In order for this to succeed, python libraries would have to be rewritten without the C API in the dialect/subset of python supported.
I wonder if erg could strive to use a subset of python mostly and innovate narrowly in just a couple of places to make python more functional.
- Common stuff (opening files, dealing with databases, string processing, math, regexps) is very easy. Sane defaults.
- Works well with the existing C ecosystem. It's not a "rewrite everything in X" language.
- It's everywhere, most machines run Python just fine.
- It doesn't treat Windows like a second-class citizen.
- It doesn't force upon you a programming model that you might or might not care about. It's not a puzzle language where everything is a monad, or everything is a class, or everything is some weird widget. Write the damn code.
- I'm personally not a fan of the language itself, but it's mostly a bog-standard algol if you don't poke it too much. It's relatively standard, people just get it even if Python isn't their main language.
- Very personal point, but it's the only language I can edit with a plain text editor. Think nano, vi, Windows Notepad, that kind of thing. I don't know what to tell you, maybe it's my tiny monkey brain, but I can't do the same in Java or C++. Not that it's my preferred way to edit software, but I like having that option in a pinch.
At least for what I do (developer, but with a data engineering/data science flavor) the overall architecture is usually the important thing, so admittedly some downsides might hit me less.
I'd still rather write medium-to-large pieces of software (say 10,000+ LOC) in something else (Java, C#, C++, something boring like that), but it's pretty much unbeatable for small programs as far as I'm concerned.
Yeah, I second this. There is some foot guns you'll hit in python, but the amount of foot guns I've hit in C++ and golang are 10x that of python.
The other thing is that over time, the python devs actually strive to make development easier, and they try to resolve foot guns where they can. In golang, e.g., Rob Pike is very opinionated about how software should be written, and it's carried forward in the language. Python on the other hand, recommends people be "pythonic", but only encourages it, and doesn't enforce it upon the user.
> I'd still rather write medium-to-large pieces of software (say 10,000+ LOC) in something else (Java, C#, C++, something boring like that), but it's pretty much unbeatable for small programs as far as I'm concerned.
What I've learned is the python requires unit tests, as does golang, or basically any language that can throw a null pointer err.
If you write your code modularly and have good unit tests around your code, it works amazingly well. I've been a part of good and bad large python projects. The best ones have really good unit tests around their code.
Python's internals are also relatively accessible and easy to work with, so it's smooth sailing once you have that need. The language starts out easy, and grows with you. Of the languages I've tried (and there are many), only Smalltalk and the Lisp family were comparable in expressiveness.
The language mostly gets out of my way and lets me do what I want. I don't feel like I have to fight the compiler (at least until I tried Mypy) or write a lot of tediously verbose boilerplate just to get out a "Hello, World!" like I did in Java.
Unlike, say, JavaScript, Python is pretty strongly typed and fails fast. The stack traces almost always point you to the exact location of the problem (unlike the JS tendency to propagate `undefined` everywhere). There aren't a lot of surprises or gotchas. I can pretty much run it in my head just by reading the code and be right most of the time. I cannot say the same for C++ or JavaScript, which naturally tend to become inscrutable without discipline.
And then there's the fact that Python has significant characters that are literally unreadable because they're invisible (semantic whitespace).
It's the community. Network effect looms large.
While typing is dynamic, I rarely see this being used, perhaps with the exception of identifying empty variables with None. Most identifiers are born and die the same type. It would be interesting to see how much effect dynamic typing has on the rate of programming errors.
Also, for me, Jupyter is huge.
Dynamic typing and changing the type of a variable are orthogonal.
You can change a type with casting, coercion, transmutation, dynamic dispatch, downcasting, reflection, monkeypatching (i.e. simultaneosly using dynamic dispatch and downcasting and reflection). All of these methods are available in Rust, which is a statically typed language.
Some things that some people think are changing the type of a variable in Python is not what it seems, for example:
# Python
a = 1
a = ['h','i'] # `a: int` is unchanged but gets implicitly shadowed by `a: list[str]`
a[1] = "a" # We're combining shadowing with weird and inconsistent scoping
translates to the following in Rust: // Rust
#[allow(unused_mut, unused_variables)]
{
let mut a = 1;
let mut a = ["h", "i"]; // Explicit shadowing
a[1] = "a"; // We're simply calling a mutating operator
}
Furthermore: # Python
lst: Array[Any] = [1, "2", 3.0] # A heterogeneous list
for elem in lst:
print(elem);
translates to the following in Rust: // Rust
// Below `dyn` has nothing whatsoever to do with dynamic typing.
// ... it is just fluff having to do with the requirements of systems programming.
// ... (Technically it means we're using vtables to do dynamic dispatch.)
// ... The `Box` nonsense is more systems dev fluff having to do with memory allocation.
// ... Of course in Rust, App devs often don't need to worry about such fluff because
// ... lib devs should provide ergonomic API's, but I'm doing as close as
// ... possible to a direct translation of the Pyhon code.
#[allow(unused_mut)]
let mut lst: Vec<Box<dyn Display>> = vec![
Box::new(1),
Box::new("1"),
Box::new(1.0),
];
for elem in lst {
println!("{elem}");
}
The one major difference between the Python code and Rust code above is that `Display` in Rust is a Rust trait (i.e. a typeclass) and typeclasses don't exist in Python.Objectively, none of these languages are particularly good at what they do and there are other languages that tend to be preferred by people who code for a living. But these are harder to learn and have higher barrier for entry. You typically need some theoretical background and experience.
I've used all of the above BTW. I learned programming using the manual that came with my Commodore 64 in the eighties (Basic, obviously). I kind of like Python for some things. Javascript is fine for simple things. None of these are my first choice of language but I can work with these languages. They are very approachable languages. Just open an editor and start adapting code.
There's a lot of language snobbery out there where objectively, the advantages aren't that huge or dramatic as people like to believe.
More modern statically typed languages can be quite easy to use (I am thinking of Scala) but none provides an ecosystem as rich as python's.
Plus, recent static languages (Scala, Rust, Haskell or even Elm) are more oriented toward "Software Engineers" or CS academics. Python appeals to a lot of "programmers" who's main job is actually data science, mechanical engineering, biologist...
I think when FP languages and paradigms become the norm (you can quote me on this, I predict that it's only a matter of time), preferences will change. People tend to prefer what they know, and it will take some time for culture to change.
I agree that working with Python code from an undisciplined/sloppy/inexperienced developer can be a pain (although in those situations I've found code from those same developers in others languages to be a problem too, but maybe worse in Python? I dunno), but in the hands of a solid dev, Python code is so readable and easy to follow, that to me code in other languages often feels much noisier. YMMV of course.
Also, in Python integers do not overflow, unlike in Rust, C and other buggy languages.
If you name a language, with high probability Python will be better in something unless it is about performance.
What I don't like: no type hints in many libraries, some libraries are not type-hint friendly, lot of unnecessary dynmamic features (like being able to patch modules in runtime) and absolutely no caring about performance and being able to compile into machine code.
> trying to figure out what some dynamically typed code is doing
There should be type hints.
About 5 years ago python was incredible. You could pop out a project quickly because there were very few packages that made breaking changes over their development, so you could often use your standard workflow with the set of packages you we're comfortable with, even if there were new versions available that day.
Now, Nvidia and Google ruined everything. Python is the ML language, so every package likely depends somehow on tensorflow or some GPU acceleration. This is a problem because every damn version of ' insert tf/pytorch/Jax/cuda/etc ml package here' only works with that exact version configuration ONLY ( and honestly, it probably doesn't actually work anyway). So, if you have an idea of using two packages together that aren't already in a package - be prepared to spend the next month trying in despair to get that to work (and probably ultimately give up).
It's insane to me that the workflow of today necessitates (in python anyway) setting up multiple docker containers to talk to each other, simply because python packages seem to have no problem making breaking changes every freaking week.
"Hey, this variable is probably of this type. Now go on, run the code and launch a debugger the same way you would if there was no hint just to make sure it's correct. Oh, and don't forget to check all the possible code paths that lead to this to make sure you've exhausted all possibilities."
Don't get me wrong, type hints are cool but they're just a toy compared to proper static typing.
Second I needed to redirect scikitlearn logging to a file. Which did not work because scikit does not use logging but something homegrown. We just overwrite the internal log function and all was good.
Yes it's seldom needed and it's a very sharp sword but it's much better that it's there when you need it. I encountered bugs in .net stdlib which where there was no alternative than to wait for the next release. Very ugly when you need to ship.
After programming in Nim (and Python back in the day), I've become used to being able to detect integer overflows as a normal exception. At least for signed ints, since not all CPU support efficient overflow detection on unsigned ints. Its handy to to let uints wrap as sometimes thats what you want. I figured all new languages would do similar things.
There is no such thing as a buggy language. Software can be buggy (or language implementation), but not the language. And the reason you do not have integer overflow is because integers are implemented as integer objects of arbitrary size, which is great if you're doing something quick and dirty, but could be disastrous for a serious work.
>There should be type hints.
So, is it one or the other?
My background was originally in C# then Java (plus JavaScript on the side, since most of us have to do that), and when I first came to Python I found it to be a lovely language and a breath of fresh air.
I guess I would say to me it feels neat and tidy, thoughful about interface design, and gives me a sense of quality. I get a similar feeling from Clojure (perhaps even more so).
I don't find static typing as valuable as you do, and additionally I find the cost in verbosity and in time wasted solving type-checking puzzles quite painful. Perhaps if I'd spent more time with one of the more sophisticated type systems I'd feel differently (Java and C# are quite limited here), but not convinced enough to try.
I think this is a problem in both static and dynamic languages and is pretty much solved in the same way: you test your code.
- Django is a robust, batteries-included web framework that doesn't have an analog in, for example, Rust.
now you can have succint code and fast repl (ala sml) but you don't get the libs
These aren't just some third-party tools bolted on. The type annotation syntax is built into the language[5] and standard library[6][7].
I personally find static typing to be more trouble than it's worth most of the time. Industry typing metalanguages are not expressive enough to deal with even fairly basic real-world programs and force you to write bad code to work around the type checker's stupidity. And, of course, you still have to write tests. Maybe someday they'll catch up to Idris. Python's static typing is no better, but at least it allows you to turn it off when it's not worth it.
[1]: https://github.com/microsoft/pyright
[2]: https://github.com/python/mypy
[3]: https://github.com/google/pytype
[4]: https://github.com/facebook/pyre-check
[5]: https://peps.python.org/pep-3107/
[6]: https://peps.python.org/pep-0484/
[7]: https://docs.python.org/3/library/typing.html#module-typing
I honestly don't see that. Could you provide some examples?
* Download and just run doesn't work. (e.g. Node, dotnet, cargo do this well). Hell, I've generally had more success with C++ in this regard.
* The syntax can be used in an extremely terse way, and that terseness seems to be idiomatic.
So you'll end up with everything you import being `any` which is not really any better than just using Python.