Hacker Newsnew | past | comments | ask | show | jobs | submit | _ZeD_'s commentslogin

What's wrong with metal spoons?

Nothing, I'm just not a metal worker.

Sooo... Is this a post about python envy?


Honestly I don't buy it. Worse, this is one of the reason I prefer to do "minimal integration tests" instead of unit tests. Take the example snippet of code

    def get_user_settings() -> str:
        with open(Path("~/settings.json").expanduser()) as f:
            return json.load(f)

    def add_two_settings() -> int:
        settings = get_user_settings()
        return settings["opt1"] + settings["opt2"]
and the very first comment just below

>>> The thing we want to avoid is opening a real file

and then the article goes and goes around patching stdlib stuff etc.

But instead I would suggest the real way to test it is to actually create the damn file, fill it with the "normal" (fixed) content and then run the damn test.

This is because after years of battling against mocks of various sort I find that creating the "real" resource is actually less finicky than monkeypatching stuff around.

Apart from that; yeah, sure the code should be refactored and the paths / resources moved out of the "pure logical" steps, but 1) this is an example and 2) this is the reality of most of the actual code, just 10x more complex and 100x more costly to refactor.


That works fine for files, but what if the integration is with a third party service for example?

You can create an actual mock networked service but it's much more work.

I think this is an example explaining what seems like a good practice for using mocks in python to me, the actual code in the post is barely "supporting cast".


If it's HTTP you can create the fixtures and serve them with a mock server. I'm a frontend dev, so backend APIs are like 3rd parties to me.

I use a browser extension for scraping actual backend responses, which downloads them with a filename convention the mock server understands. I mostly use it for development, but also for setting up screenshot tests. For example,

  PATCH /select

  'api/user(locked-out).GET.423.json'
screenshot the app and pixel diff it

  PATCH /select

  'api/user.GET.200.json'

screenshot…


> I use a browser extension for scraping actual backend responses

Can you tell the name of the extension ?



You can automate it with the right libraries, such as https://github.com/kevin1024/vcrpy

This one runs the real request and saves the response, faking it later by returning what it saved instead of making the request again.


gosh...

        try {
            val user = authService.register(registrationRequest.email, registrationRequest.password)

            return user
        } catch (exception: Exception) {
            // log exception
            throw exception
        }


no, no, no!

the whole point of the exceptions (and moreso of the unchecked ones) is to be transparent!

if you don't know what to do with an exception do NOT try to handle it

that snippet should just be

    return authService.register(registrationRequest.email, registrationRequest.password)


I'm gonna plug my favorite note on this topic: https://ericlippert.com/2008/09/10/vexing-exceptions/

Both snippets suffer from being too limited. The first, as you point out, catches too many exceptions. But the second.... What happens if the email address is taken? That's hardly exceptional, but it's an exception that the caller has to handle. Your natural response might be to check if the email address is taken before calling register, but that's just a race condition now. So you really need a result-returning function, or to catch some (but probably not all) of the possible exceptions from the method.


The way I usually structure it is that the only exception would be some type of failure to connect. Any actual error thrown by the service comes back as a result.error, and any failure (like email address taken) comes back as result.fail. This way you can separate it into (1) connection problem, (2) backend error/bug/database offline/etc, (3) both of those are fine but the backend doesn't like the input.


I agree, this was just a sample code to show how usually imperative if / else / try / catch code is written. What is also possible is we catch the exception, log it and throw another one.


I'm still waiting for the american "freedom" people to actually use all the firearms they have ammassed against the oppressing power


As a person from an authoritarian country, I should say that firearms mean much less than coordination. Organized group of 100 with no guns is stronger than 10000 armed but poorly coordinated people.

In other words, a "well regulated Militia" in the Second Amendment is more important than "bear arms".

But no one talks about creating a Militia (yet) for some reason.


> But no one talks about creating a Militia (yet) for some reason.

The line between "private militia" and "terrorism" isn't very well defined. If the people are unsuccessful, they will be labeled as terrorists and potentially put to death. Most people don't want to be executed, and as far as I am aware there's only been one successful violent insurrection in the US [1], so the odds are very much not in your favor.

[1] https://en.wikipedia.org/wiki/Wilmington_massacre#Aftermath


You probably meant "insurrection" instead of "terrorism". Terrorism is trying to achieve some goals by means of terror.

E.g. separatism (like Texan or Californian) can be named insurrection.


No I meant terrorism. If you were doing a violent attack on the federal government in order to try and get them to stop policies you don't like, I do not see a fundamental difference between that and terrorism.


No, attack on _forces_ (army, national guard, police etc) will not be recognized terrorism, most likely. Those forces are assumed to not get afraid. Of course, I can imagine something like that that might be considered terrorism, but it's a long stretch, don't remember any cases. Terrorism is almost always directed towards civilians.

Also when a force commits terror acts against other force (e.g. Russian military maiming captured PoWs) -- that's a war crime, not a terrorism either.

And why we so quick to jump to "attack"? There is a huge area the Militia can do without "attack"s. Sabotage, road blocks, building blocks, detention. Detention is violence, but it's not attack.

PS: of course the other side may call it "terror", that's for sure.


> PS: of course the other side may call it "terror", that's for sure.

That's sort of what I'm getting at. I do think you could consider some of it terrorism in the classical definition of the word in that it would be ideologically motivated and it would be done by a comparatively small set of people. I don't think an attack on a big institution is a disqualifier either, considering that some people consider Guy Fawkes a terrorist [1], and he was trying to blow up British Parliament. If you have a small group of people using armed force in order to coerce politicians to act in a certain way, I don't think it's necessarily a stretch to call it terrorism.

Regardless, even if it doesn't fit into the classical definition of "terrorism" (though I really think we're splitting hairs on this and it's getting into "distinction without a difference" territory), there is no doubt that the Trump administration would classify all these people as terrorists and try and impose any and all "anti terrorism" legislation possible.

To be clear, I'm not assigning a value judgement to this, I don't think definitions like "good" or "bad" really work here.

[1] https://www.royalholloway.ac.uk/research-and-education/depar...


As a person who was previously involved with the (somewhat more "casual") parts of the American militia movement - meaning all the right-wingers with guns - I should note that they do have some organization. Not much of it, to be fair, but generally speaking they at least know of other neighboring groups and have points of contact to coordinate "when it's time". There are also some people involved into all this that specifically go around lecturing those militias and helping them network. In my state (WA), ten years ago, these guys were affiliated with Matt Shea, and were organizing to bring supplies to firefighters during the fire season as a front of sorts. But they were pretty clear about the real nature of the org in the lecture that I've been in.

So the reality of the situation is that the vast majority of US gun owners, especially if you look at who owns "tactical" guns and gear (a 3-round hunting rifle is one thing, an AR with a full 7-mag loadout in a plate carrier is a very different one) are people who actively support the present government, or castigate them for not going far enough. So the relatively small groups of armed lefties - mostly hard left, anarchists, SRA, some Black groups like NAAGA etc; but very few liberals and mainstream progressives - are largely inconsequential.


> Organized group of 100 with no guns is stronger than 10000 armed but poorly coordinated people.

What examples are you drawing from when making this conclusion?

> In other words, a "well regulated Militia" in the Second Amendment is more important than "bear arms".

Originally standing armies were not allowed. Each state was expected to perform it's own defense. The governor could create and disband a militia to defend the state. It was expected they would appear with their own arms.

> But no one talks about creating a Militia (yet) for some reason.

Subservient to what power?


> The governor could create and disband a militia to defend the state.

so you’re saying a governor could declare their state to be under attack and organize a militia maybe even using state funds?


Just because the government is enforcing laws you don't like does not make it oppression. Imagine if everyone started using firearms in response to laws they considered oppressive, e.g. business owners who found regulation oppressive might say "come and enforce it". You would probably refer to this as "undermining democracy" if it was a law that you actually agreed with.


I think if you were to look at how often a government is rebuffed by the courts, that's a pretty good indicator of how much they're trying to bend the rules or outright ignore them.

Also, "come and enforce it" is not undermining democracy. A law is only a piece of paper until a court upholds it. Even the federal government can write whatever it wants, if it's then ruled unconstitutional that's the end of that.

The problem going on right now is that so much is being broken that the already slow court system just cannot keep up.


Using firearms against the state never works. However, the oppression isn't in the enforcement of laws it is in how those laws are being enforced, selectively, against brown and black people. Also, something being a law doesn't make it right or just. For examples of this just look at slavery, women's suffrage, civil rights, etc at a certain point in time all of those things were against the law but people agonized, organized and resisted enough to change the law. By your logic those groups weren't oppressed since the law allowed for their oppression.


How do you feel about slave catchers enforcing the law back in the day?


False equivalence. The scenario with immigration is more like: Someone builds a house on your land. You tell the cops to kick them out. Protesters disrupt the cops, stating: "OMG you'll make them homeless!"


It does when it's the courts say the government is breaking the law.


[flagged]


Please don't fulminate or post inflammatory rhetoric like this on HN. And we don't need to use Grawlix like "bl@(k" here, it's ugly and unnecessary; we can use complete words here, no matter what they are.


That's the first comment the account has made in over a decade. Considering it's regurgitating Bluesky brain rot, it's likely controlled by a bot/troll farm.


> This is the wrong take. Economic dependence on China is a massive national security threat.

and instead dependence on the U.S.?


How does it makes sense?


and yet not one of them has a monitor of 17" or more...


Top five are 18". Are you sure?


> artisan croissants [...] “emblem of French gastronomy,”

and yet italian cornetti are better grin


why it should happen?


Intelligence.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: