• 0 Posts
  • 36 Comments
Joined 2 years ago
cake
Cake day: July 7th, 2023

help-circle






  • from X import *

    That’s malpractice in most cases, and thankfully, becoming more rare to find in the wild. Any decent linter will shout at you for using star imports.

    What he’s trying to do is to get people to not use non-LTR approaces when designing APIs.

    Then he should have picked examples of APIs that break this, not use the built-in functions. Because as it reads now, it seems he is just against established conventions for purism.

    this problem is huge in C libraries

    yeah, one of my favorite things about python is that everything not in the language itself is either defined in the file, or explicitly imported. Unless, like mentioned, you have anti-patterns like star imports and scripts messing with globals().



  • Eager Eagle@lemmy.worldtoTechnology@lemmy.worldLeft to Right Programming
    link
    fedilink
    English
    arrow-up
    3
    arrow-down
    1
    ·
    edit-2
    21 hours ago

    The example of a string length function could be replaced by any other API

    I don’t know about that, len is a built-in – like str, abs, bool. There are only a few of them and they’re well known by people familiar to the language (which seems to exclude the article author). Their use is more about the language itself than about what to expect from a particular API.

    In fact, most Python APIs that go beyond built-in usage actually look much more object-oriented with “left-to-right” object.method() calls. So this argument seems silly and goes away with some familiarity with that language.


  • People don’t, in fact, read code from top to bottom, left to right

    100% this.

    This false premise is also why a few (objectively wrong) people defend writing long essays: functions with hundreds of lines and files with thousands; saying “then you don’t have to go back and forth to read it”, when in fact, no one should be reading it like a novel in the first place.

    Once you get used with list and dict comprehensions, they read just fine. Much like the functional approach is not really that readable for a newcomer either.


  • Eager Eagle@lemmy.worldtoTechnology@lemmy.worldLeft to Right Programming
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    3
    ·
    edit-2
    1 day ago

    IMO all those examples are less readable than writing it in an imperative way using good function and variable names.

    Also, len() is a Python convention and a built-in function that calls __len__() on that object. It’s even more established than .length in JS, so I really don’t see why someone would expect anything else. And even then, one could call my_list.__len__() if they really wanted to be sure and have that “left to right” bonus.



  • If it’s just a few hundred lines, sure. They work better with smaller context and sometimes they bring up something I didn’t think about. But if your goal is refactoring, I’d work with a code agent, static checkers, and automated tests to do it instead of asking for a code review.

    And if your IDE/editor can do something deterministically (e.g. renaming a method and its references), use that instead of asking an AI (or at least an AI with MCP endpoints that do it deterministically too).