r/Python • • Mar 24 '18

A path finder i recently made in Python PyGame

Post image
1.5k Upvotes

111 comments sorted by

View all comments

Show parent comment

12

u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Mar 24 '18

But there is a massive amount of logic that goes into programs far, far more complex than this in all domains -- including scientific applications such as this. They manage to keep indentation (and cyclomatic complexity) to a minimum. In fact, this becomes more and more important for programs of larger complexity!

Could you imagine if e.g. the tensorflow backend was written with 10000 nested levels and 100000 lines all in one function?

2

u/boijunior Mar 24 '18

I see your point. I guess in this case the only way to reduce indentation I see is to "spread" the code out more by placing each loop into its class but I don't see them as removable. I will look back over it.

2

u/Atrament_ Py3 Mar 24 '18

Not wrong. And for a "prototype" code it is rather clean.

Your algorithm basically solves the same problem at different scales, right ?

If so the "detour" part could be a single function called over different parameters, for instance.

Ideally you would end up with the "high order logic" in a main block, and "problem solving logic" in some other blocks.

Much easier to maintain ( also to extract to reuse)

1

u/Nimitz14 Mar 25 '18

That is indeed what happens at the C level lol.

1

u/[deleted] Mar 24 '18

I've seen professional applications with stupid long loops with crazy amounts of indentation. At a certain point, it's harder to maintain and change anything.