News for hackers. Stuff that matters.
Re:Throw away code by millstone on Friday September 25, 2020 @04:46PM (#24593927)
I could not imagine choosing Rust for the use case described. I think it's one of the worst possible choices!

Python has so many advantages for throwaway code with quick iteration. Duck typing. Easy string indexing. Bignum arithmetic by default. Trivial mutable globals. Default parameters. Trivial to make reference cycles. Access variables by name. Exceptions. And the big one is eval().

Re:Throw away code by dmurray on Friday September 25, 2020 @07:13PM (#24595017)
That's what makes the article noteworthy. There are a thousand articles of various quality out there telling you some variation on "dynamic languages are useful for prototyping and scripting, Rust/C/Java really shines in large codebases / when performance or reliability or security is important".

It didn't convince me, though. There were a lot of "this tool or library or feature exists in Rust", but no comparative advantage over other languages more compelling than this:

> This certainly is in part because I’m more proficient in Rust than in Python. It’s also because the Rust mental model is closer to how my brain works than the Python one.

Re:Throw away code by m45t3r on Friday September 25, 2020 @11:03PM (#24596088)
Also I really like Python stdlib for those kinda of throwaway scripts. While `cargo` is a far better tool than `pip` for dealing with dependencies, if you don't need to dependencies at all it is even easier, and most times when using Python I don't really need to install any third party libraries even when doing non-trivial stuff (i.e.: sometime ago I did a script that scrapped a page for a download link for some APK and sideloaded it to my Android smartphone).

Someone also said the REPL, and while the REPL in Python is not as powerful as, i.e.: Clojure, it is still something that feels essential for a exploratory workflow that is the scripts case. Testing is not the same, it is much slower to interact, specially when you just want to check a hypothesis (also, most scripts I don't want to write tests, they will probably break anyway in a few months like the example of web scrapping I said above).

Re:Throw away code by heavyset_go on Saturday September 26, 2020 @12:43AM (#24596487)
> Someone also said the REPL, and while the REPL in Python is not as powerful as, i.e.: Clojure, it is still something that feels essential for a exploratory workflow that is the scripts case.

Check out IPython if you haven't, the REPL is a game changer.

Re:Throw away code by sullyj3 on Saturday September 26, 2020 @04:24AM (#24597248)
What features make it a game changer for you? For me it felt like just a small quality of life improvement, but I've never delved that deeply into its feature set.
Re:Throw away code by heavyset_go on Saturday September 26, 2020 @04:50PM (#24602013)
- readline functionality and history

- Hints and completions behind the Tab key

- Syntax highlighting as you type, along with auto-indentation

- Dynamic introspection with "?" and "??"

- Being able to run shell commands with "!" and capturing their output with "!!"

- Magic commands behind "%" and "%%"

- File system navigation

Re:Throw away code by m45t3r on Saturday September 26, 2020 @11:03AM (#24599340)
I know IPython, and yeah, it is very nice. But most of the time I just to test something fast the default REPL is already enough.
Re:Throw away code by mumblemumble on Friday September 25, 2020 @07:50PM (#24595215)
I don't want to disparage the pragmatic value of the features on your list, but they all pale in comparison to the one true killer feature for fast development cycles: a REPL.
Re:Throw away code by war1025 on Friday September 25, 2020 @10:35PM (#24595983)
> the one true killer feature for fast development cycles: a REPL.

I've been a python dev for about a decade.

I do use the REPL a couple times a week, but I wouldn't really call it "essential".

How do people use it that makes it so valuable?

Usually I just use it when trying to figure out how to parse some text or check what methods or properties are available on an object. Really nothing that I couldn't do in a test suite or the code itself.

Re:Throw away code by xapata on Friday September 25, 2020 @11:19PM (#24596155)
If you're not writing your code in a design that lets you run parts of it every few minutes (or more frequently), you're missing out. Best way to avoid bugs in your module: don't put them in there. Find out in the REPL before you put code in the .py file.

Also, it's more important the more data-dependent your code is.

Re:Throw away code by SPBS on Friday September 25, 2020 @11:52PM (#24596276)
Tests also have the advantage of input automation. They have the disadvantage that you can't poke around at the environment once they're done (unless you drop into a debugger).
Re:Throw away code by lukeschlather on Saturday September 26, 2020 @01:01AM (#24596564)
I've found this is more and more the primary way I use the Python repl - I invoke pytest and tell it to drop me into the debugger if there's an error.
Re:Throw away code by xapata on Saturday September 26, 2020 @04:16AM (#24597214)
I usually have a test data set and run my module against it in IPython. So input is automated to some extent. If I'm analyzing the output, it can be helpful to quickly adjust charts and graphs. I'm now in the process of building distribution tests into my test suite, but it's not clear how to track everything. I need data sources essentially kept under version control, but which are generally too big for git.
Re:Throw away code by mantap on Saturday September 26, 2020 @05:18AM (#24597471)
Python has a lot of REPLs, which one in particular do you mean?
Re:Throw away code by xapata on Saturday September 26, 2020 @01:03PM (#24600315)
My personal choices are IPython and Jupyter, depending on whether I'm making plots. If you choose Jupyter, though, I caution that you should be careful you don't switch entirely away from modules and test suites. Jupyter can be too easy in a way.
Re:Throw away code by war1025 on Sunday September 27, 2020 @09:58AM (#24606632)
This sounds quite a bit different from the sort of development work I do.

I can see how a REPL would be really useful when working with data, but for building out a webserver or desktop application, it doesn't have nearly as much value.

Re:Throw away code by xapata on Sunday September 27, 2020 @03:34PM (#24609497)
And tests have less value, or at least are more difficult to write, when you're not sure if an outlier is valuable information or junk to be discarded.
Re:Throw away code by greggman3 on Saturday September 26, 2020 @05:19AM (#24597473)
I'd love to see a video of someone developing via the REPL that somehow let me "get it".

I've never written code for which I've found the REPL that useful so either my domain is not conducive to REPL usage or I need a good tutorial or example to see what I missing and how to change my approach.

Any suggested videos or articles? though i suspect a video would be better for this type of thing

Re:Throw away code by ncmncm on Saturday September 26, 2020 @01:13AM (#24596610)
Funny, that. I see the REPL as a trap. (IDEs, too, for other reasons.) REPLs are a trap because they give you the illusion of progress while mostly just wasting your time.

I am used to writing 2000 lines of code and having it run (mostly) correctly the first time. In C++, in my case. Otherwise my experience is like the author's. Types are not mainly for error checking. I demand they earn their keep as part of the solution, and they do.

Re:Throw away code by mantap on Saturday September 26, 2020 @05:24AM (#24597488)
It depends a lot on what the program is doing. Writing 2000 lines of C++ that interface with other C++ libraries and having it work first time is something I can understand.

But if you have to consume untyped input (such as parsing text), or produce untyped output (such as an image) then the value of a Notebook/REPL really shines.

Re:Throw away code by millstone on Friday September 25, 2020 @08:21PM (#24595376)
Agreed, how'd I miss that!
Re:Throw away code by gowld on Friday September 25, 2020 @07:57PM (#24595250)
REPL == eval.
Re:Throw away code by mumblemumble on Friday September 25, 2020 @09:31PM (#24595699)
eval is useful for making a repl, but there are languages with a repl and no eval (Haskell comes to mind), and there are languages like PHP that have eval but no (built-in) repl.
Re:Throw away code by greggman3 on Saturday September 26, 2020 @05:16AM (#24597462)
Hmmm, python is not installed by default on Windows. Python3 is not installed by default on MacOS. Installing them is 30+meg and now your system is "infected" with python3 (I know if you use python every day this isn't an issue to you but as someone that's not a python expert and has run into version conflicts it's no fun).

So, AFAIK rust will generate a standalone exe, python, out of the box, will not so I want to give someone else my throw away solution, not requiring them to install python to use it might be a win?

Re:Throw away code by nextos on Friday September 25, 2020 @07:38PM (#24595147)
Good type systems don't get in your way. I have often built prototypes in Scala and I felt the type system was speeding me up rather than slowing me down.
Re:Throw away code by kenhwang on Friday September 25, 2020 @08:33PM (#24595426)
I'd say that's more credit to Scala than the norm for most typed languages. Scala is an insanely productive language if you're up to speed on it.
Re:Throw away code by nicbou on Friday September 25, 2020 @06:58PM (#24594932)
Don't forget access to a huge range of mature, well-documented libraries and a large standard library.
Re:Throw away code by procparam on Friday September 25, 2020 @06:05PM (#24594590)
Can you say more about how you use eval() during prototyping?
Re:Throw away code by chaps on Friday September 25, 2020 @06:22PM (#24594724)
It can be nice when you're working running code in a repl and don't want to maintain state/code between repl sessions. If you just print the data to stdout, you can just eval it and not have to deal with writing one-off cacheing. It's similar to the use case of pdb where you're forcing yourself into the middle of ten different functions. But print statements are easily added, easily removed, and so is eval.