• h0bbl3s@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      1 month ago

      I’ve been coding around 25 years and got my start in perl. I absolutely hated python when I first used it. I use it all the time now. I still prefer my curly braces but I don’t have any trouble with python or mind the whitespace anymore. I just run it through ruff every save. I do the same with go everything goes through gofumpt. I really think a lot of it is a generational thing. Older people are just used to curly brackets.

      I do get peoples complaints about the packaging. Unless you’re a dev already it’s a bit extra to deal with shuffling virtual environments because the system python environments almost never work out of the box, at least in the last few distros I’ve used. Once I adjusted though it’s no problem. I run half my dev stuff in toolboxes with their own environment anyway.

    • uranibaba@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      I once wrote a bot in python tdownloaded a ical file, looked for chances and informed me if found. The space indentation made it hell to follow the code in my opinion.

      • naught@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        1 month ago

        Just curious, what about spaces made it hard? What language would have been easier? In curly brace languages, 99% of the time, a curly brace is followed by a line break and an indent. Python is similar except it’s typically a colon, line break, then indent.

        What I have learned is: If the code is indented too deeply, it’s a code problem, not the language.

        Torvalds infamously wrote:

        “… if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.”

        • uranibaba@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          30 days ago

          Too much nested code was likely part of the problem, but not being able to easily tell where a block of coded ended without seeing the top of the block made it difficult to work with.

          • naught@sh.itjust.works
            link
            fedilink
            arrow-up
            2
            ·
            29 days ago

            That’s fair! Takes time to get used to. Modern editors make this easier by highlighting the current indent level, or can even make the top X lines of the current closure “stick” to the top of the editor for those really long blocks.

            • uranibaba@lemmy.world
              link
              fedilink
              arrow-up
              2
              ·
              29 days ago

              Having those features would really have made it easier. I have only ever written my python code in Sublime Text. While it is a sublime text editor, at is not ideal (compared to how it is to write Java in IntelliJ) for Python. (Maybe with addons but I never delved into that more than a few.)

      • Jeena@piefed.jeena.netOP
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 month ago

        I don’t get it because my phyton code is indented exactly the same as all my other code. Each block of code one tab in/out, how else would you do it?

        • uranibaba@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          30 days ago

          It’s because there is no clear indication of where a block ends.

          Here is some sample code. I find it difficult to tell how many indentations I have or where I need to write if I want to continue at a certain level.

          import time
          import aiohttp
          
          """
          Retreives the data from RSS URL and return the status codes as well as the data. Return -1 if something went wrong.
          """
          async def get_rss_feed(rss_url):
              async with aiohttp.ClientSession() as session:
                  try:
                      retry_count = 0
                      while retry_count < 5:
                          async with session.get(rss_url) as resp:
                              if resp.status == 200:
                                  return {'status': resp.status, 'data': await resp.text()}
                              else:
                                  retry_count += 1
                                  time.sleep(60)
                      if retry_count == 5:
                          raise ValueError('To many failed connection attempts', retry_count)
                  except aiohttp.InvalidURL as error:
                      return {'status': -1, 'data': f"Error: {rss_url} is not a valid URL.", 'error': error}
                  except aiohttp.ClientConnectorError as error:
                      return {'status': -1, 'data': f"Error: Could not connect to {rss_url}.", 'error': error}
                  except ValueError as error:
                      return {'status': -1, 'data': f"Error: Could not connect to {rss_url} after {retry_count} attempts.", 'error': error}
          
    • linkhidalgogato@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 month ago

      its just not as clear especially when u are indenting stuff inside stuff with a bunch of conditions everywhere its hard to read just from indentation, and with the () or {} u can just click on it and most text editors will show u from where to where its going.

      • zalgotext@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago

        especially when u are indenting stuff inside stuff with a bunch of conditions everywhere

        That’s an anti pattern in basically every language though. The fix is to simplify those conditionals, not use a curly-bracketed language.