On Sat, Aug 18, 2018 at 7:33 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > Chris Angelico <ros...@gmail.com>: >> Programming is heavily about avoiding duplicated work. > > That is one aspect, but overcondensing and overabstracting programming > logic usually makes code less obvious to its maintainer. It is essential > to find coding idioms that communicate ideas as clearly as possible. In > some situations boilerplate and redundancy can help make the code more > robust, as not every line of code becomes a clever brainteaser.
As Steven already pointed out: > [W]hat states the intention "These methods are identical except > in their name" more strongly than creating them in a loop? What better way is there to communicate the idea "we now create ten methods according to this template" than a loop? >> Creating methods is work. Creating many identical (or similar) methods >> is duplicated work. What's wrong with using a loop to create >> functions? > > I would guess such techniques could come in handy in some framework > development but virtually never in ordinary application development. In > a word, steer clear of metaprogramming. Ah yes, because app development never has situations where lots of similar code that could benefit from metaprogramming. Blub Paradox strikes again: since you are not comfortable with metaprogramming, you never see a need for it, and when you're brought face-to-face with it, you consider it worse than the alternatives. Me, I consider it a vital feature, to the extent that I will metaprogram externally if I need to. https://github.com/Rosuav/TF2BuffBot/blob/master/drzed.sp#L23 https://github.com/Rosuav/TF2BuffBot/blob/master/gen_effects_tables.py#L118 The Python script generates a bunch of lines of code like this: sm_drzed_max_hitpoints = CreateConVar("sm_drzed_max_hitpoints", "0", "Number of hitpoints a normal character has (w/o Assault Suit) - 0 to leave at default", 0, true, 0.0); Since SourcePawn has no metaprogramming facilities other than C-style #define, I have to use a Python script that reads specially-formatted comments and generates an include file which is then compiled in. Which is better - to do that, or to have a loop that generates functions *right in the class that needs them*? ChrisA -- https://mail.python.org/mailman/listinfo/python-list