Readit News logoReadit News
ArchieMaclean commented on Clean Code vs. A Philosophy Of Software Design   github.com/johnousterhout... · Posted by u/recursivedoubts
ArchieMaclean · 10 months ago
My take on the prime example:

    import itertools
    
    def generate_n_primes(n):
        """
        Generate n prime numbers using a modified Sieve of Eratosthenes.
    
        The algorithm keeps track of a list of primes found so far,
        and a corresponding list of 'multiples', where multiples[i] is a multiple of primes[i],
        (multiples[i] is initially set to be primes[i]**2, see the optimisations section below).
    
        The main loop iterates over every integer k until enough primes have been found,
        with the following steps:
        - For each prime found so far
        - While the corresponding multiple is smaller than k, increase it by steps of the prime
        - If the multiple is now the same as k, then k is divisible by the prime -
            hence k is composite, ignore it.
        - If, for EVERY prime, the multiple is greater than k, then k isn't divisible by any
        of the primes found so far. Hence we can add it to the prime list and multiple list!
    
        There are a few optimisations that can be done:
        - We can insert 2 into primes at the start, and only iterate over every odd k from there on
        - When we're increasing the multiple, we can now increase by 2*prime instead of 1*prime,
        so that we skip over even numbers, since we are now only considering odd k
        - When we find a prime p, we add it to the prime and multiple list. However, we can instead add
        its square to the multiple list, since for any number between p and p**2, if it's
        divisible by p then it must be divisible by another prime k < p
        (i.e. it will be caught by an earlier prime in the list)
        """
    
        # Insert 2 into primes/multiples
        primes = [2]
        multiples = [4]
    
        # Iterate over odd numbers starting at 3
        for k in itertools.count(3, 2):
            # If we've found enough primes, return!
            if len(primes) >= n:
                return primes
    
            # For each prime found so far
            for i in range(len(primes)):
                # Increase its corresponding multiple in steps of 2*prime until it's >= k
                while multiples[i] < k:
                    multiples[i] += 2 * primes[i]
    
                # If its corresponding multiple == k then k is divisible by the prime
                if multiples[i] == k:
                    break
            else:
                # If k wasn't divisible by any prime, add it to the primes/multiples list
                primes.append(k)
                multiples.append(k ** 2)
    
        return primes

Some might find the docstring as well as comments too much - I find the comments help relate the code to the docstring. Open to suggestions!

ArchieMaclean commented on The game theory of seduction and marriage with Jane Austen   optimallyirrational.com/p... · Posted by u/delichon
bill_joy_fanboy · 2 years ago
> This is hopefully too cynical...

Nah, it's just how it is.

A casual web search will show that women care about money in relationships and marriage... a lot.

ArchieMaclean · 2 years ago
I'd be willing to bet that the majority of results you find in that search will be men talking about how much women care about money... of course some women do, but far far from all of them
ArchieMaclean commented on Racket: Lisp for the modern day   deusinmachina.net/p/racke... · Posted by u/Decabytes
dizhn · 2 years ago
I am getting a weird rectangular box on this website that is not allowing me to read the article in peace. My assumption was they did want me to read it, but it doesn't seem to be the case. It says "Discover more from Deus In Machina" on this box. I would maybe want to discover more except for 2 things, #1 it won't let me read the current thing, #2 i don't know that other things will let me read it either.

I think they should fix this quite obvious bug before writing more articles.

ArchieMaclean · 2 years ago
Beneath the large obvious green 'Subscribe' button there is some low-contrast grey text ('Continue reading') that, when clicked, hides the box. This is on Substack's side, not the author of the article.
ArchieMaclean commented on Your keyboard layout is broken   snprajwal.com/blog/keyboa... · Posted by u/snprajwal
dillydogg · 3 years ago
Oh shucks, I should have known you would have tried it. Sorry, I was hoping I had a silver bullet for you.
ArchieMaclean · 3 years ago
No worries, worth a try!
ArchieMaclean commented on Your keyboard layout is broken   snprajwal.com/blog/keyboa... · Posted by u/snprajwal
dillydogg · 3 years ago
You can rebind caps to backspace in GNOME. I think you use GNOME tweaks. I've done it on all of my computers.
ArchieMaclean · 3 years ago
I did this initially, but I believe it didn't work for all applications - some were still registering it as Caps Lock (e.g. VS Code IIRC).
ArchieMaclean commented on Your keyboard layout is broken   snprajwal.com/blog/keyboa... · Posted by u/snprajwal
eviks · 3 years ago
> The Colemak layout was designed with the capabilities of modern keyboards in mind

But it wasn't! Modern keyboard is precisely what the author describes in the following bullet points: split and ortho (though it shouldn't be linear, our fingers have different lengths). He also forgot to mention utilizing your strongest fingers with a thumb cluster instead of that dumb long spacebar

None of the popular QWERTY alternatives have been designed with a proper ergo keyboard in mind, not to mention all the other modern keyboard features like home row modifiers.

(I don't know of any layout development algo and its resulting layout that takes those things with an actually typed training corpus into accounts, but would be happily proven wrong)

ArchieMaclean · 3 years ago
Workman [0] was designed to be used on an ortho keyboard, though it is also usable on a normal keyboard. I suppose it's tricky to design for many modern features as they are not yet standardised between keyboards.

[0] https://workmanlayout.org/

ArchieMaclean commented on Your keyboard layout is broken   snprajwal.com/blog/keyboa... · Posted by u/snprajwal
TheAceOfHearts · 3 years ago
This article would be a lot more interesting if it also mentioned any of the downsides of switching to a non-default keyboard layout. They just mention switching to Colemark as if it's the obviously superior option and you'd be a fool for not switching. Depending on what you're doing, I hope you enjoy a lifetime of fighting with keyboard shortcuts, or having to constantly remap keyboard shortcuts for every single new program. And hopefully you're not interacting with other people's devices or having other people interact with yours, because nobody else is going to be sharing your non-default keyboard layout.

It would be cool if web browsers provided better tools for handling diverse keyboard layouts. You can implement customizable shortcuts if your app merits that level of complexity, but if you just wanna implement a few default shortcuts they can end up in really awkward positions for non-default layouts. Unfortunately for most developers supporting multiple keyboard layouts is probably really low in their priority list.

ArchieMaclean · 3 years ago
I use Colemak-DH (modified version of Colemak that has less lateral hand motion - found I was getting slight wrist strain with normal Colemak). I find it more comfortable than Qwerty. I have not had any issue with keyboard shortcuts - Ctrl-Z/X/C are in exactly the same spot and Ctrl-V is shifted over by one key. Most shortcuts are placed to be memorable (e.g. Ctrl-F for Find), not to be ergonomic, so the keyboard layout doesn't really matter. The only place I've really had to customise is Vim, where I've remapped the motion keys back to where they are in Qwerty (actually shifted over by one to j/k/l/;).

On Gnome, switching keyboard layout is very quick and easy - there's an icon in the top bar by default - so I can use that when other people want to use my computer. When I use others' computers, I have to look at the keyboard but it is not too much hassle for me as I don't do this very often.

The main issue I've actually had is remapping Caps Lock to Back Space - not trivial to do in Gnome (required creating my own layout in XDG).

ArchieMaclean commented on Gren – an Elm fork   gren-lang.org/... · Posted by u/jgilias
josephcsible · 3 years ago
There are certain operations that only "kernel" packages are allowed to do. If that weren't the case, then this would indeed be little more than an obscure quirk.
ArchieMaclean · 3 years ago
Ah I see. So non-kernel packages do not have access to native modules at all? I believe in Elm native modules were still possible, just not publishing them to the package database. But in this case I guess you wouldn't be able to put a native module in a GitHub repository and then pull this in as a dependency, which is equally rubbish.

Edit: EdwardDiego's answer clarified this for me

ArchieMaclean commented on Gren – an Elm fork   gren-lang.org/... · Posted by u/jgilias
aslilac · 3 years ago
Even worse, it checks the git history to make sure that...

- There are no changes since HEAD

- The commit is signed by Robin himself

...and for those interested in the code that does this

https://github.com/gren-lang/compiler/blob/main/builder/src/...

ArchieMaclean · 3 years ago
Correct me if I'm wrong, but that code seemingly only applies to kernel packages, i.e. packages which are made by the gren team [1]

Seems more like a check to make sure the version of the JS is compatible with the version of gren than anything else.

[1] https://github.com/gren-lang/compiler/blob/e665e521367eeedec...

ArchieMaclean commented on Why do ships use “port” and “starboard” instead of “left” and “right?”   oceanservice.noaa.gov/fac... · Posted by u/snitzr
bink · 3 years ago
ArchieMaclean · 3 years ago
Presumably it came from Latin 'puppis' (aft, stern, poop deck) before the passing through French to English.

u/ArchieMaclean

KarmaCake day282January 21, 2020View Original