Live data from Hacker News

Metaprogramming in Python

developer.ibm.com

11–20 of 61 posts

Re: Metaprogramming in Python

#11
Python is an amazing language. It's basics are very easy to learn and I'd like to think it doesn't feel like a incomprehensible sorcery to the beginner.

But even for that, it's not a toy language as clearly evident by this example.

Re: Metaprogramming in Python

#12

It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". And with the recent addition of new syntax, I would hardly call Python easy.

> It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". But that's exactly what that expression means? A car with an automatic transmission is "easy to learn and use", but an automatic transmission is way more complicated to construct than a manual one.

I wouldn't call subclasses, metaclasses and decorators easy to use, let alone learn to use correcly.

The comparison makes no sense.

Re: Metaprogramming in Python

#13

Earlier quoted context omitted.

Python is easy, not because it prevent people from doing complicated things, but because with only a few simple things, you are productive. Most python programmer use 10% of the language, the same 10% that is described in most tutorial, because that's enough, and they don't even know the rest exist. This makes for a very smooth, but long learning curve which allow you to enjoy python in the early years, yet keep gett…

That "smooth learning curve" applies when you are learning the language, use it by yourself or work in the ML/Data science industry. Once you get thrown in a big project that makes heavy use of type hinting (plus the whole environment of it, mypy et all), Object Oriented design and all those hidden things...you realize how much you really don't know. And that 10% is way too small. To be productive in Python, you need…

Using a different language isn't going to stop the vertigo of being thrown into the deep end of an existing project without a mentor to guide you through it.

Re: Metaprogramming in Python

#14

Earlier quoted context omitted.

> It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". But that's exactly what that expression means? A car with an automatic transmission is "easy to learn and use", but an automatic transmission is way more complicated to construct than a manual one.

I wouldn't call subclasses, metaclasses and decorators easy to use, let alone learn to use correcly. The comparison makes no sense.

What? Decorators are easy to use, subclasses are easy to use, and you don't need metaclasses.

Re: Metaprogramming in Python

#15

It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". And with the recent addition of new syntax, I would hardly call Python easy.

For a language that is actually "easy to learn and use", look at Lua[1].

It's so easy to learn & use that children manage to be productive with it (the Roblox community).

It's still powerful though. With few enough primitives to remain simple & understandable, it has just enough primitives to build anything. People have written web frameworks, window managers and video games in Lua.

It's got less pitfalls, "voodoo magic" and advanced weirdness than any other language I know. You can learn 90% of the language from its Wikipedia page. Every time I encounter some of Python's internal weirdness, I wish Lua had been the scripting language of the 2000s instead. Unfortunately Python has a vast collection of libraries available that keep us using it instead.

[1]https://www.lua.org/pil/contents.html

Re: Metaprogramming in Python

#16

Earlier quoted context omitted.

> It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". But that's exactly what that expression means? A car with an automatic transmission is "easy to learn and use", but an automatic transmission is way more complicated to construct than a manual one.

I wouldn't call subclasses, metaclasses and decorators easy to use, let alone learn to use correcly. The comparison makes no sense.

I read your "vodoo magic in a programming language" to mean "behind the scenes in the implementation of the programming language", not "for a programmer to understand while using the programming language".

Re: Metaprogramming in Python

#17
It’s interesting that meta programming, one of the main selling points of lisps, is actually pretty common and possible in other languages as well. Lisp’s “code = data” achieves meta programming in a straightforward way, but this link shows that it’s not necessary. In fact, Python’s way might even be better because the language sorta “gets outta the way” because it’s really darn simple.

Re: Metaprogramming in Python

#18

It is shocking how much vodoo magic there is in a programming language marketed as "easy to learn and use". And with the recent addition of new syntax, I would hardly call Python easy.

What an odd thing to say. This article is not for beginner Python programmers, and you don’t need to know anything in this article to use Python. I know people who refuse to use decorators because they seem difficult, and yet they are able to make very useful applications.

Re: Metaprogramming in Python

#19

Earlier quoted context omitted.

Python is easy, not because it prevent people from doing complicated things, but because with only a few simple things, you are productive. Most python programmer use 10% of the language, the same 10% that is described in most tutorial, because that's enough, and they don't even know the rest exist. This makes for a very smooth, but long learning curve which allow you to enjoy python in the early years, yet keep gett…

That "smooth learning curve" applies when you are learning the language, use it by yourself or work in the ML/Data science industry. Once you get thrown in a big project that makes heavy use of type hinting (plus the whole environment of it, mypy et all), Object Oriented design and all those hidden things...you realize how much you really don't know. And that 10% is way too small. To be productive in Python, you need…

If you make a big project, you will have to use that many things with every langagues. If the language is rich, you'll learn the language. If not, you'll learn the project patterns. It's not specific to python.

But 99.9999999% projects won't implement metaclasses.

Most won't event implement decorators, context managers or generators. Use them, sure.

Re: Metaprogramming in Python

#20
Stuff like this is how I created a very quick-and-dirty SaltStack module for AD Federation Services:

https://github.com/irtnog/salt-states/blob/production/_modul...

The SaltStack module starts out empty except for a function that runs at module load time. The initialization function queries PowerShell for all AD FS-related cmdlets and creates Python wrapper functions for them. It even copies the cmdlet's help to the function's docstring.

Post reply on HN