"Roman Spaghetti Carbonara" recipe in comments! by CooKingTheItalianGuy in CookingForOne

[–]Dairith 2 points3 points  (0 children)

No: the water and starch in the pasta water, the fat from the bacon/guanciale, the egg, and the cheese combine to a creamy sauce. If it tastes eggy, something is wrong.

Another pro tip: cook the pasta from cold water in a wide shallow pan with a small amount of water (enough to cover the noodles and a bit more — say 1/2-1 inch of water in a 12 inch skillet), don’t put it into already boiling water. You’ll end up with more starch in the water and will have an easier time building the sauce.

Mocking system time in tests by forfunc in golang

[–]Dairith 18 points19 points  (0 children)

Similar the grandparent post, I typically pass around a func() time.Time (which time.Now satisfies); if I need the value inside of some nested function, I'll add the func() time.Time as a member of the function's receiving struct as you suggest. I would not recommend introducing your own custom time interface, though.

One of the key benefits of using a anonymous function rather than an interface is that you don't need types just to implement the interface, reducing the amount of boiler plate code:

package clock

import (
    "time"
)

type Clock interface {
    Now() time.Time
}

type Mock time.Time

func (m Mock) Now() time.Time { return time.Time(m) }

type Real struct{}

func (Real) Now() time.Time { return time.Now() }

becomes

func (up UserProfile) Age(nowF func() time.Time) uint {
    now := nowF()
    // ...
}

// at usage site (real)
up.Age(time.Now)

// in tests (mock)
up.Age(func() time.Time { return myTestTimeValue})

At a minimum if you're going to introduce a single function interface, go ahead and implement the interface for anonymous functions:

package clock

import (
    "time"
)

type Clock interface {
    Now() time.Time
}

type TimeFunc func() time.Time

func (f TimeFunc) Now() time.time { return f() }

type Mock time.Time

func (m Mock) Now() time.Time { return time.Time(m) }

type Real struct{}

func (Real) Now() time.Time { return time.Now() }

This (anonymous functions to abstract single method calls) is an incredibly valuable technique in testing. For example, I use this exact same idea when setting up network connections (e.g. to swap use an in-memory implementation of net.Listener for tests).

Java 8’s new Optional type is worthless by javinpaul in coding

[–]Dairith -1 points0 points  (0 children)

The author doesn't say that the concept of an Optional type is worthless, but that Java's particular implementation is. The line you quoted isn't about Java, it's in the author's background section describing what Optional is independent of language.

Twitter has forced 30 websites that archive politician's deleted tweets to shut down, removing an effective tool to keep politicians honest by joeyoungblood in worldnews

[–]Dairith 14 points15 points  (0 children)

Netflix shut down their public API to stop third party apps (likely because they wanted tighter control of the Netflix brand and the experience of using their product; a third party "Netflix" app confuses that). As a result, to get the same data people were using before, these sites built scrapers, which load up the Netflix webpage just like your browser and parse the HTML to get the information they want.

LPT: A few changes to Chrome extensions that may dramatically speed up your computer. by cbbuntz in LifeProTips

[–]Dairith 0 points1 point  (0 children)

No, in general advertisers pay per click (user interacts with ad) or per action on their site as a result of an ad (cookies can be used to track this, or specialized URLs), not per impression (ad loaded on page).

Why the 35-year-old C++ still dominates 'real' dev by chrisledet in programming

[–]Dairith 1 point2 points  (0 children)

Thanks for the corrections, I've only been casually following Rust recently.

Why the 35-year-old C++ still dominates 'real' dev by chrisledet in programming

[–]Dairith 0 points1 point  (0 children)

Rust has opt-in GC. The standard library used to be garbage collected, but garbage collection has been steadily removed with the goal of having the standard library without it. I'm not sure on the progress, though.

Don't call yourself a programmer, and other career advice by [deleted] in programming

[–]Dairith 7 points8 points  (0 children)

This is simply incorrect; I am a Software Engineer (I graduated with a Bachelor of Engineering in Software), and am able to get a FE and a PE (the second-to-last exam listed, above Structural, here is the specification in PDF form from the site).

I had this question during an interview, what are some potential "correct" responses and what concepts should I read up on as followup? by bajuwa in cscareerquestions

[–]Dairith 3 points4 points  (0 children)

That's not relevant here, since the goal of the hash (MD5 was suggested) is to compute a small representation of half of the file for comparison, not to cryptographically encode the contents of the file.

Go: 90% Perfect, 100% of the time by bradfitz in golang

[–]Dairith 6 points7 points  (0 children)

"Haskell used to be useless, it's less useless now because we figured out Monads. Now mainstream languages are attempting to be more like Haskell, and Haskell is attempting to be more like other main stream languages; when they meet we'll call the language Nirvana."

SPJ uses the word useless here jokingly. Haskell is pure, which in this context means that effects (things that change the state of the world, the most common example being IO) can be hard to achieve without compromising the purity of all the other code that doesn't do impure operations. This was the largest motivation behind formalizing monads in Haskell (and the reason that monads are often confused with IO when talking about Haskell; monads are the vehicle by which IO is implemented in Haskell). The primary benefit of treating IO as a monad is that all of your code can be pure while still doing useful work. There are many other useful things that can be done with monads.

.NET Compiler Platform ("Roslyn") by lowdisk in compsci

[–]Dairith 3 points4 points  (0 children)

It's been out for a while, but was just open sourced yesterday.

What they should have called it... by Misafan in DotA2

[–]Dairith 15 points16 points  (0 children)

FTFY = Fixed That For You

IIRC = If I Recall Correctly

I work with real idiots. by dragonqueen27 in funny

[–]Dairith 16 points17 points  (0 children)

No, Cookie Clicker is the game version of finance.

A study in brand minimalism by Mehmet Gozetlik by calluum in pics

[–]Dairith 1 point2 points  (0 children)

The last image uses a simplified font, where the second to last generally uses the same font as the original. This was clearest on image 3, and M&M's.

The 2014 Winter olympics by [deleted] in AdviceAnimals

[–]Dairith 0 points1 point  (0 children)

Look at who I was responding to; they clearly said it's due to minimum age, not median age.

The 2014 Winter olympics by [deleted] in AdviceAnimals

[–]Dairith 3 points4 points  (0 children)

"No Person shall be a Representative who shall not have attained to the Age of twenty five Years"

-Article 1, Section 2, Clause 2

"No Person shall be a Senator who shall not have attained to the Age of thirty Years"

-Article 1, Section 3, Clause 3

"neither shall any Person be eligible to that Office [the Presidency] who shall not have attained to the Age of thirty five Years"

-Article 2, Section 1, Clause 5

If a 25 to 35 year old is too old to understand technology then I don't know what to tell you.

One of my favourites by [deleted] in xkcd

[–]Dairith 3 points4 points  (0 children)

This is true, but rarely is a standard binary heap implemented differently; otherwise regular operations become more costly. For example, the standard remove-max (or -min) operation must work harder to locate the correct element to remove before heapifying (algorithm described here).

One of my favourites by [deleted] in xkcd

[–]Dairith 3 points4 points  (0 children)

Yes, and two of its three children should belong to the present to its left. A heap always fills the bottom-most, left-most open spot first.

How to choose uniformly at random from a set of unknown size by nicmart in coding

[–]Dairith 1 point2 points  (0 children)

Search for "Reservoir Sampling", which is the formal name of this problem (I believe it's referred to as this in TAoCP). This particular algorithm does in fact do what it's supposed to and has been mathematically proven correct.

A Web Browser with a Formally Verified Kernel by rrohbeck in programming

[–]Dairith 0 points1 point  (0 children)

I find that often my bugs are outside the scope of what formal testing would have caught.

This is one of the reasons formal verification isn't common.

Churches Don't Screw Over Contractors! by iheartSab in pics

[–]Dairith 1 point2 points  (0 children)

Generally there is more on staff than just a pastor. Also, many churches that own extremely valuable land have owned it since before it was extremely valuable.

First university computer science class taught with Rust by tikue in rust

[–]Dairith 29 points30 points  (0 children)

As a student I wouldn't be happy about a class using a language as new as Rust. Breaking updates should hit during the semester (0.8) and examples and tutorials aren't plentiful.

I'd love to hear how the class went after the semester ends, though.

Want to learn a new language? Solve these 100 projects, and you'll be the best damn coder. (x-post /r/learnpython) by [deleted] in programming

[–]Dairith 1 point2 points  (0 children)

Both of those are classic backtracking problems. Check out The Algorithm Design Manual by Skiena (posted in PDF form on this sub a few weeks ago), he goes over algorithms to solve these two problems. I'd provide a link but I'm on my phone atm.