1. 13

  2. 7

    I would have liked to read this, but I didn’t want to make an account. Is this for monetization so that the author can get money? I’m ok with that but do sites really need me to create an account for that? Can’t they just track views?

    1. 6

      Whenever I see a page on medium, I just automatically go to archive.is and look for a cached copy.

      Here’s this one.

      If there’s no cached copy there, I request one and it takes about two minutes.

      1. 5

        Sadly that’s Medium… no idea why people use it, you can always read it with Incognito Mode in your browser.

        1. 4

          I’ve just started adding medium.com to my ad blocklist. I do wish there was a way to filter specific sites on lobste.rs like you can filter tags[1].

          [1]: I realize it wouldn’t work for this url in particular, because the linked site uses several redirects (with cookies) under the hood, as well as cloudflare – e.g. medium “custom domain”. Still would filter out quite a few though.

          1. 3

            There’s a Greasemonkey script for blocking domains and stories.

            1. 1

              That looks pretty sweet. Thanks! <3

        2. 4

          I take contention with the author’s recommendation of “Handling if-else logic”.

          The synopsis: for functions with a significant amount of branching logic it should be abstracted to a dict containing functions. I believe the reason the author recommends this is two fold:

          1. Python lacks a proper case/switch statement instead deferring to to if...elif... and
          2. maximum branches should generally be < 12.

          However, this code is not, in my opinion, Pythonic. A dict containing function pointers is more akin to Javascript than Python, wherein you’re effectively executing arbitrary code as the result of a lookup. Further, I think this approach significantly reduces the readability of the codebase. You’re now deferring logic to a multitude of other functions rather than encapsulating the unit of work inside the caller.

          I agree that Python’s lack of a switch statement is less than ideal but I ardently disagree that this “trick” is something to recommend others use.

          1. 5

            The dict approach is something that should only take place if there is more than ~10 options IMO. Sometimes it truly is the option to take, as it allows easy extensibility and can separate the code into more logical parts. But reaching 10 cases is sometimes a pointer that something else is wrong in the system, since most of the time there shouldn’t be so much different cases handled by a single piece of code. But sometime, it just has to be like that (in a parser for example) and that’s where you can use dictionaries to clean it up if you need to. Upcoming structural matching should make that choice obsolete though.

            1. 1

              Agreed on all counts.

          2. 1

            Related to the use of sets: as of 3.7 all dicts in python preserve insertion order. So if you need an ordered set you can often use a dict to get a quick and dirty one really cheaply.