• MightBeWinderz (unregistered)

    It probably behaves differently if the file system supports cased files (so ABC.details =/= abc.details and so on).

  • (nodebb)

    Assuming Path.glob does what I expect (because why would I read the docs when I can assume?), this code could raise the InternalError if it's running on a filesystem that allows literal wildcard characters in filenames. If the directory contained files named helper-for-game.details and help*me.details, then globbing help*me.details would return both files.

  • (nodebb)

    The other point is that it may well be returning the data that corresponds to an identifier that is part of the content of the file rather than part of the name of the file. That doesn't excuse the arse-about-tit way the code goes about scanning the files, but could explain why it scans all of them rather than just the one named by the identifier parameter.

  • Sauron (unregistered)

    That path is the Road of White Nettles. Follow it and horrors will reveal to yourself.

    http://thecodelesscode.com/case/33

  • Loren Pechtel (unregistered)
    Comment held for moderation.
  • Yikes (unregistered)

    Weird code that works despite how it was coded kind of reminds me of RL agents that find some glitch or non-intuitive feature to win the game.

  • Barry Margolin (github)

    Is base_path.glob a correct recounting of the code? base_path is a string, not a Path, there's no glob method. It should be glob.glob(main_file).

    I guess we're globbing because the function allows you to provide a wildcarded filename. It will process the match, but only if it's unique.

  • Sam (unregistered) in reply to Steve_The_Cynic

    The identifier in the content is the same as the file name. By definition, because the code that creates these files, written by the same author, sets the filename based on the identifier in the contents.

  • (nodebb)

    wait, there's more! if I remember correctly, dict.update(another_dict) basically "merges" the two dict, adding or overriding the keys/values of dict with the ones from another_dict (yes, I checked - https://docs.python.org/3/library/stdtypes.html#dict.update). So - ideally and if I read the whole shenanigans right - this will return the identifier value contained in the last file read that had that identifier inside! Of course the order of file read is not guaranteed by listdir, so yay for deterministic results!

  • iWantToKeepAnon (unregistered)
    Comment held for moderation.
  • Sam (unregistered) in reply to Barry Margolin

    Yes, sorry, this is a sanitisation error on my part - base_path has been coerced to a Path object by some of the logic I elided, so the method is present and this call works, it's just absurd.

  • Ryan (unregistered) in reply to Sauron

    That Road of White Nettles story was excellent. It makes a great parable even for non-developers to understand the issues of poor design.

  • ND (unregistered)
    Comment held for moderation.

Leave a comment on “Up the Garden Path”

Log In or post as a guest

Replying to comment #578988:

« Return to Article