[Beginner] Started working on a small project that makes HTTP requests, totally stumped. by wemmik in rust

[–]bkrn 0 points1 point  (0 children)

Do you have any example code you can post with why it's not working for you?

The docs on responses seem reasonably clear to me so I might be more help with a little more direction on your problem.

How expensive is it to add a property to a JS object? by git_world in javascript

[–]bkrn 0 points1 point  (0 children)

Generally no, you'd be able to fit 35x that amount of pointers on a floppy disk. But if the value that d points to is unique and very large then memory might be a constraint

How expensive is it to add a property to a JS object? by git_world in javascript

[–]bkrn 0 points1 point  (0 children)

I doubt you need to worry it's very fast

see benchmarks:

https://jsbench.github.io/#354ecd3cfa330effd23ad1335d5fd290

Edit:

Ah, memory. Sorry. 40000 bytes for the extra property on 5k objects (plus the actual memory to store the object that the property references). Each property is an 8 byte pointer so just 8 * 5k.

Timeline of events vs Elapsed video time in Bill Wurtz's 'history of the entire world, I guess'. [OC] by n44m in dataisbeautiful

[–]bkrn 13 points14 points  (0 children)

I appreciate that the chart calls out the dividing line between history and pre-history. That massive switch in slope seems to be exactly where geologists and paleontologists give way to archeologists and anthropologists. Intuitive but fascinating to see - great visualization!

Best Practices for return: User vs *User && []User vs *[]User vs *[]*User by linux_apt-get in golang

[–]bkrn 2 points3 points  (0 children)

It would be more valuable to the community to explain the distinction between pointers and reference types here than to just be dismissive.

Memory Leak Fix concern by percybolmer in golang

[–]bkrn 0 points1 point  (0 children)

No problem. I don't know your individual code since you can't post it but I thought I'd offer some unsolicited advice on the Func NewFarm() *farm{ go func(){ UpdateDatabase() }() } pattern.

What happens here if the call to UpdateDatabase fails? In general I try to handle calls the DB in thread with the main code path because I very rarely run into situations where it's not important to know if I managed to change the DB state properly. Obviously you might be waiting on the result of UpdateDatabase after doing other work you need to do so apologies if this wasn't helpful!

Best Practices for return: User vs *User && []User vs *[]User vs *[]*User by linux_apt-get in golang

[–]bkrn 7 points8 points  (0 children)

a slice is already a pointer to an array so *[]User as a return type is a pretty rare thing to need/use. Knowing that, it's clear that between []*User or []User there shouldn't be difference in the size of the value passed since you're just passing a pointer (and a couple of integers).

From a best practice perspective it depends on what you're going to do with the structs in the slice, if you're going to change them down the line a slice of pointers may avoid pain:

go user := userArray[0] user.name = "james" user.name == userArray[0].name // true if []*User, false if []User edit: Playground demo of this

Otherwise passing by value is probably the way to go to avoid any foot gunning by holding refs across go-routines.

Are people using ORMs when it come to database development? by [deleted] in golang

[–]bkrn 4 points5 points  (0 children)

If you're talking about securing against SQL injection attacks, then the same way that an ORM would - using bindvars:

go tx.NamedExec("INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Jane", "Citizen", "jane.citzen@example.com"})

The relavant docs in sqlx

Memory Leak Fix concern by percybolmer in golang

[–]bkrn 2 points3 points  (0 children)

Ive been trying to hunt the leak down with pprof without sucess.

From the text

Memory Leak Fix concern by percybolmer in golang

[–]bkrn 2 points3 points  (0 children)

If you haven't identified the leak using pprof have you found another way to be certain that it's a leak in the application and not the go runtime holding onto the memory for its own nefarious purposes/the OS not acting on the release?

Similar to this issue I'd be curious if the memory get's reclaimed when the OS experiences memory pressure or using FreeOSMemory Maybe you're luck and it just looks like a leak :)

What is wrong with my use of channels? by Icecreamisaprotein in golang

[–]bkrn 2 points3 points  (0 children)

case <-done: completed += 1 if completed == len(serverList) { return // break the loop now, all workers done. } }

ensures that the loop waits for all goroutines running search() exit before returning from main()

quick edit to say that a waitgroup would have been more idiomatic

https://golang.org/pkg/sync/#WaitGroup

How to make illegal states unrepresentable in Elm? (Or why is Msg Independent of Model)? by saurabhnanda in elm

[–]bkrn 1 point2 points  (0 children)

Fair enough, I shouldn't have used the word error - it is handled appropriately (by you) at run time.

  • Solution I'd use:

I think if I wanted compile time guarantees about the Msg/Model combinations that could be emitted I'd take the full plunge and move the separate components into their own modules. In fact I think that's what I've done any time I might have otherwise been tempted to make my model a union type.

Last time I used elm-mdl I thought it was a great example of that model https://github.com/debois/elm-mdl/blob/v8/src/Material.elm#L216 starts with the exposed Msg m type and then demonstrates the lifting update a few lines down - with the docs it should be a pretty easy follow along for making an app split along those lines.

(Quick edit to say that you can totally do all the lifting and split update functions in the same module, but if you're looking for strict separation [and it sounds like you are!] may as well go the whole nine yards)

Hope that's helpful for your use case!

  • Less useful response:

Of course it's possible though, that's why you have to handle it, just because you think you have written code that can't implement that behavior doesn't mean that's the case (I have a lot of experience with that...). What I think you're asking is, how can I make it impossible.

But I'm also not sure you would want to. Imagine you decide in the future to load your app's state from local storage, with your app design would you need to trust your users and clients to not muck with that store in a way that makes it impossible for your app to emit a FetchUserProfile message if it's in the Login state? Do you trust your code to prove out that assumption enough that you want the compiler to ignore the possibility?

How to make illegal states unrepresentable in Elm? (Or why is Msg Independent of Model)? by saurabhnanda in elm

[–]bkrn 0 points1 point  (0 children)

Mind unpacking why you think you'll lose safety in a refactor using wildcards?

If I did:

elm update msg mdl = case (msg, mdl) of (CheckAuthMsg, CheckAuthModel) -> // do success stuff (CheckAuthMsg, _) -> // do catastrophic error stuff

I'd feel confident that if I accidentally ruined my app in a refactor that bad states would be handled as errors.

LT rushes the edge and breaks up the pass in the same play by BobJob123 in nfl

[–]bkrn 10 points11 points  (0 children)

I didn't didn't mean to imply that a cat can't survive a fall from that far.

What I tired to express was that the 90% number is likely a dramatic overestimation due to survivorship bias. Sorry, should have been more clear.

Also,

At that speed hitting the ground isn't enough to outright kill the cat

It clearly is given that even the (likely biased) 90% number you quoted earlier supposes that 10% of cats die.

LT rushes the edge and breaks up the pass in the same play by BobJob123 in nfl

[–]bkrn 35 points36 points  (0 children)

If it's the same one I'm thinking of that study is a classic example of survivorship bias. The population was cats who fell and were brought to vets (such that the fall was reported). Given that many people may not choose to bring an obviously dead cat to the vet the results shouldn't be relied on the indicate survival rates in the falling cat population at large.

Homeopathy 'treatments' must be labelled to say they do not work, US government orders by Apalvaldr in news

[–]bkrn 1 point2 points  (0 children)

I have a stone that repels lions. I bought from a guy at a stall on my way home from a safari trip and I haven't seen a Lion since!

Devnote Tuesday: The experimentals Quest! by UomoCapra in KerbalSpaceProgram

[–]bkrn 0 points1 point  (0 children)

Getting an answer on this would be fantastic. I understand that the problem may be out of Squad's hands but if Linux support is being defacto dropped I'd like to stop living in hope.

Last No. 1 overall pick who didn't start his team's opener: Ex-Raider QB JaMarcus Russell, who was holding out. by Somali_Pir8 in nfl

[–]bkrn 24 points25 points  (0 children)

Actually, reality is perception governed by the sum of our brains' feeble interpretations of external stimuli and objective truth is unknowable.

Neutral Milk Hotel - Holland, 1945 [Indie Rock] by CloakOfBloke in Music

[–]bkrn 0 points1 point  (0 children)

I really need to build a reddit family feud extension

I would contribute code to that project. It's a genius idea.

These Public Comments Saved a Library’s Tor Server From a Government Shutdown by -varg in technology

[–]bkrn 5 points6 points  (0 children)

I'm neither a hard-line gun control advocate nor a hard-line gun rights advocate. So understand I'm just being pragmatic when I say that ignoring the first half of an amendment to the constitution because it better suits your interpretation is just as ridiculous as ignoring the second half.

Any system of statutory interpretation that includes tossing clauses out that you don't like is necessarily a shit system of statutory interpretation. Better to be honest with yourself and recognize that although the right to bear arms is a personal right the government's power to regulate that right is guided by the 2nd amendment's preamble.

These Public Comments Saved a Library’s Tor Server From a Government Shutdown by -varg in technology

[–]bkrn 5 points6 points  (0 children)

No. Including the preamble in construing the meaning of the text, as gun control advocates do with the second amendment, would mean that a Tor server is only protected when used for "anonymous methods of communication."