#Rate my Python codestyle

10 messages · Page 1 of 1 (latest)

rough needle
#

I'm very used to C and C++ and code in python usually destroys my eyes.
But I found some way to return these brackets in Python. The following code was written by deepseek by my instruction, was slightly edited and wasn't tested.

import sys;
import threading;


class NoGILDemo :#
  def __init__(self) :#
    self.counter = 0;
  #;

  def increment(self) :#
  #.
    # This would be thread-safe without GIL
    for _ in range(100000) :#
      self.counter += 1;
    #;
  #;
#;


def main() :#
#.
  if (sys.version_info >= (3, 14)) :#
    print("Running Python 3.14+");
#;
  else :#
    print("Python 3.14+ required for GIL-less execution");
    return;
  #;

  demo = NoGILDemo();
  threads = [];

  for i in range(10) :#
    t = threading.Thread(target=demo.increment);
    threads.append(t);
    t.start();
  #;

  for t in threads :#
    t.join();
  #;

  print(f"Final counter value: {demo.counter}");
#;


if (__name__ == "__main__") :#
  main();
#;
sour pilot
#

When you code in Python! You code in Python , not C++ or C

#

This code works for you , but never deploy this code and share it with others!

#

Why would you use a class? Generally in Python you use a class when you want want to group similar kind of data!

#

And a function when you are making actions , taking an input -> producing an input!

#

And generalyl a functional paradigm is the one you wanna overall go with and specially when you are new to Python , as things can get really confusing and weird for you if you don't understand Python OOP that good!

rough needle
#

The really bad thing is that python is everywhere. For example I think blender would be better with luajit scripting engine rather than Python, but alas, it's too deeply integrated and it's too difficult to add another scripting language into it. I even consulted at blender matrix chat.
So, I would use that style to code my extensions for blender. This is like a License. If you use my python code - it will be with C-like braces scratch

rough needle
#

I mean, C leaves the freedom to choose indentation and it generally follows the same thing: 4 spaces or 2 spaces. python does this strictly and solely with indentation