HNHacker News
TopNewBestAskShowJobs

useerup

710 karma · joined October 29, 2014

submissionscomments
useerup··on Beautiful ideas in programming: generators and continuations
In C#:

    static IEnumerable<int> Fibonacci()  
    {  
        int first = 0;  
        int second = 1;  
      
        yield return first;  
        yield return second;  
      
        while (true)  
        {  
            (first, second) = (second, second + first);  
            yield return second;  
        }  
    }
useerup··on Beautiful ideas in programming: generators and continuations
Exception handlers are continuations.
useerup··on I had to give a wrong answer to get the job (2017)
It meant something before Rails bastardized it.

Until then (and thanks to Smalltalk) it was a composite UI design pattern combining observable and mediator patterns. It was also a recursive pattern, in which the "editor" could itself be a model-view-controller.

Rails designers completely misunderstood it (or deliberately ignored it) and simply reused the terms for something that was only marginally similar, not recursive and was not inherently "active".

Other frameworks adopted Rails' terminology and now we are left with the original pattern having been completely forgotten.

useerup··on Klarna users are being signed in to random accounts
> and easy to spot

Not always. Like if you initialize middleware by using a "lambda" (closure), and you from within that closure creates a new closure.

It means that you need to be aware of the context the outer closure is used in. If it is only instantiated once during initialization, it's free variables are in essence "hidden" global variables. Not easy to spot.

useerup··on Klarna users are being signed in to random accounts
I've seen something like this happen because of a race issue during login. Basically the developer(s) had refactored something and were not aware that a global variable was being captured by a closure used for auth.

This meant that whenever two users signed in at the exact same time, there was a non-negligible chance that they swapped accounts during the flow.

It was actually not that easy to spot in the code. Sometimes what looks really, really stupid on the surface may in fact have a complicated and not-so-stupid explanation, often involving multiple developers and modernizing legacy code.

If it is a race condition, it can be incredibly hard to find during test.

Even if it is a stupid mistake, like e.g. not marking session cookies as secure and private, it does not mean that all of the rest of the code is bonkers.

useerup··on How Lucky Is Too Lucky in Minecraft?
You are entitled to your own opinion, but not to your own facts. The mathematical fact is that Dreams feat is so incredibly unlikely that (as illustrated in the video you refuse to watch):

*If every single human being on planet Earth each completed a Minecraft speedrun every single second for 100 years (no sleep), the chance anyone during those 100 years getting as lucky as Dream just once is less than 1:1000.*

useerup··on 50 Years of Pascal and Delphi Is in Power
The forerunner for Delphi was Turbo Pascal. Before it became Turbo Pascal it was called Compass Pascal and then Poly Pascal (it was sold by a danish shop/company called Poly Data).

Anders Hejlsberg wrote the first Compass Pascal compiler when he was 16. And it still lives on in Delphi so many years later. Anders is now driving TypeScript development at Microsoft.

useerup··on Microsoft Power Fx – A low-code general purpose programming language
LoadData is not lazy loading. It is explicit loading.

Maybe you should have digged a little further. To lazy load related entities you would have to declare the navigational properties virtual.

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/proxies

    Note that the EF will not create proxies for types where there is nothing for the proxy to do.
    This means that you can also avoid proxies by having types that are sealed and/or 
    have no virtual properties.</quote>
This is a common rookie mistake, unfortunately.

Entity Framework is an absolutely top-tier ORM (if you like ORMs). Because lazy loading is frowned upon by some purists (and DBAs), EF also support controlled/eager loading where nothing happens (lazily) behind the scene.

You can - for instance - in the query use <code>.Include(x => x.RelatedEntity)</code> to load a related entity eagerly without going back to the database server to load the related entity for each row (the so-called N+1 problem).

useerup··on Dominion Voting Systems Sues Rudy Giuliani
Actually, there were claims made about massive voter fraud in the 2016 election: When Trump could not stomach the fact that he lost the popular vote, he claimed that more than 3 million ineligible voters had voted for Clinton and that he had in fact won the popular vote.

There was even a voter-fraud commission set up to investigate the claims. They quietly disbanded.

useerup··on Dominion Voting Systems Sues Rudy Giuliani
The entire state of Georgia. where Guiliani alledged that votes were "switched" by Dominion machines, were in fact hand counted and affirmed the machine-counted tally.

Even after the hand-count clearly confirmed that the machines had not switched any votes, Guiliani spread the same lie. This is actually documented in the suit.

Mind you, it is not that the vote-tally machines leave a paper audit trail. The vote-tally machines work by scanning the actual paper ballots.

useerup··on Dominion Voting Systems Sues Rudy Giuliani
Baseless means that there is no proof of the allegations. Dominion is under no obligation to prove the that the election was fair. Guiliani now have the opportunity through discovery to support his allegations, or at least the was in good faith. If he fails to do so he risk being on the hook for $1B+.

It is curious that of all his public allegations against Dominion, he never asserted those in court. He is a lawyer and is aware of the consequences of asserting false accusations or frivolous suits in court. No doubt he will point to Sidney Powell and claim he was in good faith.

Most of the claims he made were pretty outlandish, and IMO he (especially as a lawyer) should now better. This is going to be interesting.

He publicly claimed that the Dominion machines "switched votes" even after the hand-count in Georgia confirmed that the machine count had indeed been accurate.

useerup··on Haskell is a Bad Programming Language (2020)
Quicksort in one line:

    Quicksort = { []->[], [p,,m]->this(m??<p) + (m??==p) + this(m??>p) }
useerup··on Danes Get 20-Year 0% Mortgages
There's a property tax of 1% for home values up to around DKK 3M, and 3% for the value above 3M.

That is the based on the "official estimated value", however, which is typically conservative and lagging and therefore somewhat less (like e.g. 60%) of what the property actually sells for.

The 3M is set so that the vast majority of homes will not exceed this value.

In addition to that we pay a "lot tax" which varies by municipality between 1.6% -3.4% of the value of the lot without the buildings.

useerup··on Danes Get 20-Year 0% Mortgages
Danes can deduct around 25% of paid interests (and "contribution fees" on mortgages). A little more for paid interests below DKK 50000 yearly and a little less for paid interests above DKK 50000.

A typical home can sell for DKK 4M. With a 20 year 0% interest and 80% of the 4M mortgaged (the maximum allowed), the "contribution fee" would be set at 0,75%.

That would amount to interests (0%) and "contribution fee" (0.75%) yearly around DKK 24000 (1st year) of which 25% = DKK 6000 will be deductible.

To put that into perspective:

A. An average "medium level" worker will have an average income of DKK 466,660/year[1] and pay DKK 159,212 in taxes, leaving a post-taxes income of DKK 307,448.

B. An unemployed will receive DKK 225,894/year and pay DKK 58,952 in taxes, leaving a post-taxes income of DKK 166.942

So in reality the mortgage tax deduction does not amount to much. With those low interest rates it is around DKK 6000 or DKK 500/month for a typical family.

Compare DKK 6000/year or DKK 500/month to: - a pair of Levi's: DKK 660 - a 4G/5G plan with 50GB/month: DKK 160/month - iPhone 12: DKK 7000

[1] https://www.dst.dk/en/Statistik/emner/arbejde-indkomst-og-fo...

useerup··on Danes Get 20-Year 0% Mortgages
I have -0.28% on a mortgage which will be refinanced every 5 year. The lenders actually pay me to store their capital. Weird times.

In actuality, though, I also pay a 0.5% "contribution" fee which covers mortgage company administration and collective risk. So the effective rate is around 0.22%.

For the 20y bonds the 0% interest is also just the actual bond rate. The administration fee will have to be added.

The "contribution" fee rate depends on how much of the home value has been mortgaged. Below 60% it is typically around 0.5% because of the relatively low risk (you can probably always auction off the house at get at least 60% even in bad times). When mortgaged from 60 to 80% of the home value the fee is higher.

useerup··on Common security issues with crypto websites and APIs
> No matter what variation of auth token you are using, make sure you are not just encoding BASE64 of user data like user ID and some timestamp.

Seriously, at the end of 2020 this kind of advice is necessary?

useerup··on Microsoft is working on an Android subsystem for Windows 10
> Microsoft filed an Amicus brief supporting Oracles view that API's are copyrightable

No, actually Microsoft filed an amicus brief supporting Google's view:

https://www.supremecourt.gov/DocketPDF/18/18-956/89566/20190...

useerup··on Anders Tegnell defends Sweden's virus approach
> Sweden is just marginally worse off against Covid overall than the US. And they didn’t have to spend $4 trillion or lose 40 million jobs to achieve that.

Sweden took less drastic action than the US. Sweden did take some action early, encouraging social distancing, increased hand hygiene etc. Then again, in Sweden you can take sick leave with full pay. More people will stay home if they feel sick.

Parts of the US took more drastic actions, but very, very late (during a pandemic where number of cases double every 4-5 days, one week is late, several weeks is very late). Shutting down borders to foreigners doesn't cut it when the virus is already spreading in the communities.

While they ended up in almost the same place, you really cannot compare them. The Swedish circumstances are so different from those of the US, that you cannot expect the Swedish same strategy to work the same way in the US.

And before you claim that the Swedish strategy is a success, consider how Sweden compares to its Nordic neighbors, where you can compare the circumstances.

Per 1,000,000 inhabitants:

    Sweden  4042 cases, 450 deaths
    Denmark 2040 cases, 101 deaths
    Finland 1247 cases,  58 deaths
    Norway  1567 cases,  44 deaths
useerup··on Boeing cutting more than 12,000 U.S. jobs with thousands more planned
The A-320 was a runaway success which threatened to shut Boeing out of that segment. Boeing needed to do something, and fast. Hence the 737-MAX as a stop-gap until they could come up with a better competitor.

Yes, the A-380 (different segment) did poorly. Boeing actually had a nice thing going for them with the 787.

useerup··on Linux is Most Used OS in Microsoft Azure – over 50 percent of VM cores
> RegEdit, is there a text version for that?

Uhm, in Powershell:

    PS C:\Users\zb3> cd hklm:
    PS HKLM:\>
(you are now in the registry local machine hive)
useerup··on Linux is Most Used OS in Microsoft Azure – over 50 percent of VM cores
Windows IO model - including network - is arguably much more well designed than anything POSIX, thanks not least to Dave Cutler and his team.

From the get-go Windows NT (Win32) had a common model for overlapped IO (async IO in today's parlance). This async capability permeated everything from disk IO to network IO, and works well today with USB, Thunderbolt etc. Mind you, this model has not changed while Unix/Linux/POSIX still have not found a common model that works for all. See for instance https://stackoverflow.com/questions/13407542/is-there-really...

Under the hood Windows was also designed with a completion-oriented model (IO completion ports) which scales better in most instances than the Linux readiness-oriented approach (I believe that MacOS uses a completion approach as well, so the readiness approach is not universal *nix). Basically, windows saves at least one context switch for every basic IO operation. Windows supports the Berkeley sockets API with some optional extensions to make socket operations overlapped/async as well, essentially supporting both the straight socket model as well as the completion oriented extensions.

useerup··on Ultraviolet Irradiation of Blood: “The Cure That Time Forgot”? (2018)
No, just a reckless idiot.
useerup··on Is the room open?
PowerShell solution:

    1..[Math]::Sqrt(500) | %{$_*$_}

    1
    4
    9
    16
    25
    36
    49
    64
    81
    100
    121
    144
    169
    196
    225
    256
    289
    324
    361
    400
    441
    484
useerup··on A common mistake involving wildcards and the find command
> just type "Could-We-Make-It-Even-More-Verbose -PerhapsInTheNextVersionWeWill!"

PowerShell can be as terse as bash. Just use the aliases (which are actually real aliases in PowerShell), leverage default parameters and shorten parameter names (or use their aliases) to just use enough character to disambiguate.

To get a file listing of your directory, simply type

    ls
If you want to know why this works, type

    help ls
and PowerShell will answer you with the help on "Get-ChildItem".

You could also type this to explain the `ls` command:

    gcm ls
And PowerShell will answer

    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Alias           ls -> Get-ChildItem
`gcm` is itself an alias for Get-Command - a command that gets information about a command. Executing `gcm gcm` will produce this output:

    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Alias           gcm -> Get-Command
Incidentally, why does `find` have a `--delete` option in the first place? That's not very do one thing only and do it well. `find` should search/find and do that well. Why is it also a file-deleter?

Going back to the example from TFA, in PowerShell you would delete files not matching a pattern using this command:

    ls -ex *.py -rec -file | rm
Or, if you do want it verbose, using full names instead of aliases and shortened parameter names:

    Get-ChildItem -Exclude *.py -Recurse -File | Remove-Item
useerup··on Ask HN: Favorite trait of your programming language/framework of choice?
Language Integrated Query (LINQ) of C#

LINQ is actually enabled through a number of language features, but most importantly is perhaps the ability to "cast" an expression as an "expression tree" (an AST), allowing code to inspect the expression, extract, change, rebuild and finally compile. This is what enables a library such as Entity Framework to do accept in-language queries, extract clauses and generate efficient SQL where clauses, cross joins etc.

useerup··on Local Privilege Escalation in OpenBSD's Dynamic Loader
This. setuid/SUID root was - and still is - a terrible idea. It is a (deliberate) hole in the security barrier. It was an idea spawned out of necessity because of the limited expressiveness of the standard Unix security model.

Once you let a process run with root or other elevated capabilities, that process should be isolated so nothing about the process can be controlled by the unprivileged user. SUID root utilities violates that.

useerup··on Threads can infect each other with their low priority
> Because Windows and Linux are not designed for hard real time.

True, although RT kernels have been developed for both.

Windows actually features Autoboost (Priority Inheritance). As Windows also has IO priority, the boost also applies to IO operations, boosting both the thread priority as well as the IO request priority of the lock owner, when a higher-priority thread blocks on a mutex owned by a lower-priority thread.

useerup··on Base64 encoding and decoding at almost the speed of a memory copy
While it is correct that memory is orders og magnitudes slower than modern cpus, this is also why cpus sport multiple levels of caches.

memcpy operations (and base 64 encoding/decoding) are highly "local" operations. When the segment of memory they operate on has been placed in the cpu level1 or level2 caches, the operation is much faster and will not need to access main memory for each byte/word. Only when a memory barrier is encountered will the cpu need to flush/refresh to/from main memory.

useerup··on Trump Will End California’s Authority to Set Stricter Auto Emissions Rules
Not just destroy the environment. The US car industry will have a hard time developing and manufactoring cars which can be exported. Practically every other market will have stricter norms. China is betting big on electric cars, setting domestic restrictions forcing the Chinese car industry to innovate.

Then, the US will argue that the trade deficit is "unfair", while the real reason that markets will not buy US goods is that the products are anachronistic, sub-standard junk.

useerup··on List comprehensions across languages (2007)
pet peeve, but at least the C# examples (and probably others as well) can IMHO be written more elegantly:

Example 1:

    static IEnumerable<int> GetEvenNumbers(IEnumerable<int> l) => l.Where(x => x%2 == 0)

Example 2:

    static IEnumerable<FileInfo> GetFilesGreaterThan(int size,string directory)
    {
      DirectoryInfo dirInfo = new DirectoryInfo(directory);
      return dirInfo.GetFiles().Where(x => x.Length >= size)
    }


Example 3:

    static void SolveProblem()
    {
        var results = 
        from a in Enumerable.Range(0,9)
        from b in Enumerable.Range(0,9)
        from c in Enumerable.Range(0,9)
        from d in Enumerable.Range(0,9)
        where (1000*a + 100*b + 10*c + d)*4 == 
            (1000*d + 100*c + 10*b + a) 
            && a != 0
        select new {A=a,B=b,C=c,D=d};

        foreach(var r in results) {
            Console.WriteLine($"A={r.A} B={r.B} C={r.C} D={r.D}");
        }
    }
One important point is not to confuse List and IEnumerable of .NET. What is called "lists" in many languages are actually more akin to IEnumerable in .NET
← PreviousPage 2 of 7Next →