News for hackers. Stuff that matters.
Re:Writing Snake in 12 Lines of PyTorch by alberth on Thursday August 11, 2022 @02:37PM (#32429949)
Is writing X in Y lines of code having any real meaning? I'm not trying to be negative, just genuinely asking.

For example, in 1-line-of-code I can write "hello world". This hello world is physically lighting up individual pixels on my display. It's rendering the letters to be the shape "hello world" should be. It has antialiasing applied. All in 1 line of code!!!

Re:Writing Snake in 12 Lines of PyTorch by qsort on Thursday August 11, 2022 @02:42PM (#32430019)
It has some merit when you are comparing different solutions. For example (and I know people loathe python on here, I'm just using it for the sake of example, please bear with me), writing a simple web service in python takes fewer lines of code than doing the same in say, Rust.

This doesn't imply that a language is better than another, it's just an objective fact one might find useful to keep in mind.

The article's usage is admittedly clickbait, another recent article that popped up on the home page was titled something to the effect of "Speech Recognition in 100 lines of C++". Predictably, it turned out that they depend on a multi-million-line library.

Re:Writing Snake in 12 Lines of PyTorch by alberth on Thursday August 11, 2022 @02:51PM (#32430114)
But if you're importing in a library that might have 100,000 LoC just so that you can say you "wrote X in 12 LoC" ... is that really a far representation?
Re:Writing Snake in 12 Lines of PyTorch by qsort on Thursday August 11, 2022 @02:56PM (#32430170)
Yes, that's my point. What these articles do is effectively to "hijack" that metric.
Re:Writing Snake in 12 Lines of PyTorch by selcuka on Thursday August 11, 2022 @07:34PM (#32433138)
This article is more honest, though. It only imports PyTorch and that is already mentioned in the title.
Re:Writing Snake in 12 Lines of PyTorch by eliasffyksen on Thursday August 11, 2022 @02:56PM (#32430173)
I wrote more for the fun of it than anything else. The challenge was just getting it as small as possible, just for the sake of it
Re:Writing Snake in 12 Lines of PyTorch by auraham on Friday August 12, 2022 @01:09AM (#32434907)
I think that if someone can condense an algorithm using just a bunch of lines of code, that reflects a deep understanding of the problem domain. A lot of people can code an algorithm using a lot of lines of code. But it requires practice and experience to write short and expressive code. For example, Karpathy is famous for this, you can check his implementation of evolution strategies [1].

[1] https://openai.com/blog/evolution-strategies/

Re:Writing Snake in 12 Lines of PyTorch by ratg13 on Thursday August 11, 2022 @04:26PM (#32431282)