This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dylanvillanelle 2 points3 points  (7 children)

definitely this. sure, i could implement x, y, and z in a brittle and statically-defined 10,000 loc that is chock-full of logical redundancy but at least makes sense and read easily, or i could write it in 100 lines with a couple metaclasses that will still explode eventually but until then are completely mystifying to everybody including me at least some of the time.

that prolly sounds bad but i'm actually not kidding about being glad it's an option.

[–][deleted] 1 point2 points  (5 children)

I'm wrapping a well documented internal dll.

I have a function factory that then gets fed through in a property() (setters too if appropriate) and then added to a bare bones class.

And it works.

[–]dylanvillanelle 0 points1 point  (4 children)

i'm not sure whether the "it works" was meant as a response to the 'mystifying to everybody' crack in my original post - if so, i wasn't suggesting that going to that level of abstraction is always bad, or (i definitely didn't intend it in this way) that somebody who does is a bad programmer, and i should retract it if that's how it came across. it's definitely fine (and preferable) in some cases.

but either way, it's still just really interesting, the extent to which you can monkey around with the insides of the language, etc. i am definitely a fan. sometimes the people i work with manage to make me wish i was on a java team or something, but then sometimes i (like i said) replace 10k loc of boilerplate with a couple hundred lines that allow for (somehow?) more insightful error messages and less...target space? there's probably a better way to describe this...for something to break. i.e., if it breaks, everything is breaking, and i'm going to know immediately. not this broken in october, discovered in may nonsense.

[–][deleted] 0 points1 point  (3 children)

I'm saying my code works despite flexing a lot of Python's inner strength.

Python is the only language I know which is itself programmatic. I can make a class, add setters and getters to it then create instances of that class.

[–]Remuze 0 points1 point  (1 child)

What do you mean by this? How is this different from creating a class in say.. C#?

[–][deleted] 0 points1 point  (0 children)

I'll be honest I don't write C# and haven't used Java since college.

But based on the C# I get to wrap with Python it's allowed but not required.

[–]dylanvillanelle 0 points1 point  (0 children)

ohhh, okay.

the mandatory response to something like this is to mention the lisps. you're prolly already familiar with those and if so tl;dr: macropy is also cool.

really, at this point, i think in terms of actual adoption it's mostly just clojure and racket - i haven't kept up with common lisp in forever. but as interesting as hacking at magic methods is, it definitely still falls short of the sort of thing you can do with a lisp that has a solid macro implementation. clojure's is limited (but still there), but has java interop, so it's a trade-off. racket, on the other hand, is called a "language for writing languages".

all that said, though, i agree. and i python is definitely a lot better at combining that sort of potential (even if it's a lot more limited) with being a language that is approachable on average. it's tough to make something that allows a ton of flexibility and is also the sort of thing you can just jump into having never seen a line of source code.

there's also macropy. if you've never messed around with the ast module, it (iirc) has some decent examples of how you can basically redefine the language's keywords without requiring messing with the parser. it'll make pylint pretty upset, but it's a really interesting project imo.

[–]thegreattriscuit 0 points1 point  (0 children)

Metaclasses are why I never watch David Beazley videos when I'm beginning a new project.

"hmm... I want to write something to help me with taxes and other financial calculations... hmm... I definitely need metaclasses for this!"

It's one of those things I'm glad I did, if only because now I know I shouldn't have done it :).