4
$\begingroup$

The Blender Best Practices: Style Guide has a number of scripting recomendations, including the use of pep8.

Quoting PEP 8, beautiful code, and the tyranny of guidelines.

Getting PEP 8'ed

Once a standard exists, there’s a great temptation to impose that standard on other people’s code arbitrarily. You might even believe you’re doing the world a favor.

The PEP 8 standards warn against this with a quote from Ralph Waldo Emmerson: “A foolish consistency is the hobgoblin of little minds”. But that doesn’t stop eager PEP 8ers diving in and complyifying other developers’ code. Once we know how to do something — and we believe it’s useful and productive — we’ll be tempted to jump in and do it wherever we can. Thus once somebody knows how, they can’t help but perpetrate PEP 8.

With any guideline: follow it yourself sooner than impose it on others.

Why?, later in the comments to this answer @David commented how readable the answer code is. Agreed it is "cobolically" readable, BUT is a travesty against the pep8 rules... the thin edge of the wedge ...

Just this small snippet produces the following pep8 report.

for f in range(1,animLen + 1):
    S.frame_set( f ) # Set frame

    frmNum   = str( f ).zfill(3) # Formats 5 --> 005
    fileName = "angle_{a}_frm_{f}".format( a = angle, f = frmNum )
    fileName += S.render.file_extension
    bpy.context.scene.render.filepath = join( renderFolder, fileName )

# |2| 21: E201 whitespace after '('
# |2| 23: E202 whitespace before ')'
# |2| 25: E261 at least two spaces before inline comment
# |4| 15: E221 multiple spaces before operator
# |4| 24: E201 whitespace after '('
# |4| 26: E202 whitespace before ')'
# |4| 37: E261 at least two spaces before inline comment
# |5| 47: E201 whitespace after '('
# |5| 49: E251 unexpected spaces around keyword / parameter equals
# |5| 51: E251 unexpected spaces around keyword / parameter equals
# |5| 60: E251 unexpected spaces around keyword / parameter equals
# |5| 62: E251 unexpected spaces around keyword / parameter equals
# |5| 69: E202 whitespace before ')'
# |7| 50: E201 whitespace after '('
# |7| 73: E202 whitespace before ')'

The usage of dislike( this ) has started to proliferate. How do others feel about this. Should some form of coding standard (pep8, tlousky2017, lol) be adhered to on BSE, or is it open slather?

$\endgroup$
3
$\begingroup$

I think the effort required to globally enforce something like this will be much larger than any conceivable gain is worth:

  • Lots of existing code which likely doesn't follow spec

  • New users are arriving all the time; likely won't know (or care) about it

  • As you say, code snippets don't have to be standardized to be understood.

  • Being understood is the primary goal for most code snippets here; they usually are intended to demonstrate a concept rather than function as a complete implementation.

On the other hand, editing to improve clarity, readability, and accuracy is something which should always be advocated. While enforcing an entire standard on a global level might not be very productive or practical, editing individual answers which you personally feel could be worded (or coded) in a clearer manner is absolutely something to encourage!


I personally dislike( this ) as well ;)
But then again, I'm also the kind of person who's too lazy to write spaces in their-css:rules;.

$\endgroup$
  • $\begingroup$ "With any guideline: follow it yourself sooner than impose it on others." is probably the go I suppose. I'm certainly too lazy to bother pepifying others' code snippets $\endgroup$ – batFINGER Mar 21 '17 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .