eatonphil / lisp-rosetta-stone

A lisp rosetta stone to demonstrate modern language features
171 stars 11 forks source link

Un-idiomatic Python #8

Open sohang3112 opened 7 months ago

sohang3112 commented 7 months ago

The Python code can be improved & made more idiomatic.

For example, this class code:

class Token():
    value: str
    kind: TokenKind

    def __init__(self, value, kind):
        self.value = value
        self.kind = kind

is much better written as just:

from dataclasses import dataclass

class Token():
    value: str
    kind: TokenKind

Similarly for Sexp class.

Aeron commented 7 months ago

Considering the existing PRs, it’s unlikely there will be any improvement to this code. As all benchmarks or similar measuring means, these are biased as well. There is a certain point that needs to be proven.

And you can’t really argue here because code verbosity and readability are very subjective, even having all the language style guides. It’s easy to dismiss almost any proposed revisions as not readable enough.

Can it be improved with data classes or named tuples? Yes. How about generators? Yes. Will it ever be made? I honestly doubt that. Maybe I’m mistaken.

(I came here from the original Twitter thread about Rust, which makes sense in many ways, but this example rubbed me the wrong way. Not to wage a war or have a beef, though. Simply passing by.)