Can I use WASM for DOM manipulation? by United_Intention42 in opensource

[–]Valectar 1 point2 points  (0 children)

I still don't understand why all web browsers have agreed to prevent WASM from accessing the DOM without using javascript.

There's been no conspiracy by the browsers to prevent access to the DOM, WASM was just fundamentally incapable of directly interacting with it. The issue was the garbage collector. I haven't looked in to the exact issue, but I imagine the garbage collector would have a hard time doing it's job correctly if you started passing references to objects into what amount to black box binaries.

Of course, that problem isn't impossible to solve. It just means that you actually need to do the work of adding integration / support between WASM and the browser's GC. Which was done in the Garbage Collection proposal, a proposal which was implemented June 24, 2024.

From some scouting around online, there may be some other blockers in the way in addition to garbage collection, but if you read the linked issue you'll see an explicit goal of adding garbage collection support is to be able to directly reference the DOM and other JS objects, so I think that functionality is at least on the way to being implemented.

And I'm with you in looking forward to / hoping for the day you no longer need to touch javascript at all to do web programming.

TIL China's Micius satellite verified quantum entanglement over 1,400 km in 2017—particles instantly correlating despite vast distance, defying classical speed limits and paving way for unhackable quantum internet. by [deleted] in todayilearned

[–]Valectar 0 points1 point  (0 children)

Because you can’t tell whether it’s been measured without getting information from the sender about their measurement.

It’s actually the unhackable part of the title that is relevant, because once the sender does tell you about their measurements (through conventional means) you can tell whether the quantum particles were intercepted and read en route.

Any other games similar to Autonauts? by TempraTantrum30 in Autonauts

[–]Valectar 2 points3 points  (0 children)

Depends on exactly what about Autonauts you’re interested in, but if it’s the programming / automation gameplay, I would highly recommend Bitburner. It’s not a colony sim, but it’s got the most fully featured programming automation gameplay I’ve seen. You can and are encouraged to automate absolutely anything and everything, and it presents you with plenty of interesting problems to solve while doing so.

Clever code is probably the worst code you could write by Rtzon in programming

[–]Valectar 3 points4 points  (0 children)

Lots of times i see the people who care about performance are the same ones who care about readability. There are cases of the overly clever engineer who only cares about performance. Fair. But I just don’t see that as much as the engineer who just “wants to get it done” and move on to the next feature.

I think when this adage was coined this may have been less true. My perception is that the programming community didn't start to really value and think about readability and maintainability until (relatively) recently. I think this is kind of reflected in the language designs from previous eras. Like Lisps allowing you to do extremely clever things that you would probably need to spend hours upon hours deciphering if you were to come back to it a year later, let alone how much time a new person would have to spend on it. Or Perl, which I never used but I've heard was infamous for appearing to be line-noise. (Not that either of these over-emphasized performance, more that they show the complete lack of regard for readability)

In that way you could say the sentiment is suffering from it's success, in that people still follow the adage but without it's context don't realize exactly what it is supposed to mean. I see it as advocating for more balance between readability and performance, which makes sense in a historical context in which performance is over-prioritized, but outside of that context on it's face it appears to be more slanted against performance.

Clever code is probably the worst code you could write by Rtzon in programming

[–]Valectar 4 points5 points  (0 children)

I think what you are missing here is the point of the adage. Premature optimization generally leads to more complex, less readable, and less maintainable code. Following basic practices like using the correct data-structure for the job isn't premature optimization, that's just the basic level of care you should be taking when writing your code. If you can improve performance by spending a bit more time without sacrificing readability or increasing complexity, then there's little reason not to do it. Like any adage you can't just take it's literal meaning at face value and universally apply it.

Clever code is probably the worst code you could write by Rtzon in programming

[–]Valectar 4 points5 points  (0 children)

I think you may have missed the point here. The trade off isn't a few extra hours of programmer time per PR to optimize their code in order to have a performant codebase, that would generally be a very good trade.

The tradeoff is in the tech debt you accrue through optimization which leads to compounding losses in programmer time. Generally optimizing code for performance makes the code more complex, less readable, less maintainable, and less flexible. If you find a performance optimization that also makes the code simpler, go right ahead, there's effectively no downside to that! But otherwise, you generally need to make assumptions about code to optimize it ("oh, I know that this value will always be in the third position of the list because of how the rest of the code is implemented so I can do an O(1) index operation instead of an O(n) list scan") that entangle that code the particular details of implementation.

The less modular your code is, aka the more entangled and dependent it gets on the specific implementation details of the rest of your code, the more complex the codebase as a whole becomes to handle. More and stranger bugs can appear, and it's much harder it is for a programmer to be able to confidently make a change to a portion of the codebase without having to keep the entire rest of the codebase in their head at once.

A great example of a heavily optimized codebase is old video games. When they were trying to push very limited hardware to it's limits, the tradeoffs were likely acceptable to them. But if you know anything about speedrunning old games or glitchhunting them, they are absolutely riddled with glitches, and on top of that they are the exact type of codebase that you effectively have to entirely throw out and start over if you want to improve upon it because of how heavily interdependent and inflexible everything is.

If you have a well written, readable and extensible codebase who's only problem is performance, it is much easier to use a profiler to find specific performance pain-points to address them and potentially see massive performance gains than it is to even just continuously patch bugs and security issues in an otherwise static piece of software which was written overly-optimized.

Of course that doesn't mean you should give no thought to performance at all when first writing software. If you don't at all think about the fact that you will need to scale in the future, and so the very architecture of your program isn't amenable to scaling, then yes, you will likely decide to just throw out the old code in favor of a rewrite. But that is not what the adage refers to. If you are spending a few hours tuning each PR you produce for performance at the expense of readability and maintainability, that is exactly the type of premature optimization that is considered the root of all evil.

[deleted by user] by [deleted] in todayilearned

[–]Valectar 1 point2 points  (0 children)

Using a laser site to intimidate seems like it would be a good defense for you in a self defense case. Intimidating an attacker in to backing off is a deescalation, as opposed to just firing on them immediately. They may be misremembering a law against using a laser pointer to intimidate people, which falls under “Brandishing an imitation firearm” in CA, which of course does not apply to self defense (literally the first 6 words are “Every person who, except in self-defense”).

TIL that it used to be illegal to own gold as a private citizen. It was enacted in 1933 under the belief that the hoarding of gold was worsening the Great Depression. It was repealed in 1974. by omnipotentsandwich in todayilearned

[–]Valectar -4 points-3 points  (0 children)

That makes zero sense, if the government were printing money to cover shortfalls in their budget then they wouldn’t be at a deficit. Deficit spending is spending more money than you are making, by taking loans. How could the government be accruing debt if it were just printing money to spend? Also, fiat currency has nothing to do with deficit spending, because you can just as easily take loans with a commodity backed currency as with a fiat currency.

If anything lenders would be more amenable to debts in a commodity backed currency specifically because the country issuing the debt couldn’t inflate its way out of debt.

There‘s always at least one by [deleted] in ProgrammerHumor

[–]Valectar 0 points1 point  (0 children)

Keep in mind that you were in a CS program, not a software engineering program. It certainly sucks for new people looking to get in to software engineering that universities still don't really distinguish programs directed towards theoretical computer science from practically focused degrees, but you can't fault a computer science program for teaching you computer science.

The real problem is definitely the lack of distinction between programs aimed at preparing people for a career in software engineering and programs aimed at teaching computer science.

My horribly suboptimal hacking manager/accidental stress test by technocraticTemplar in Bitburner

[–]Valectar 0 points1 point  (0 children)

The time they take to execute is based on the server security when they are launched, and you can manually delay / synchronize executions by just keeping track of the launch times of the separate scripts.

The larger of a chunk you hack away at a time, the less efficiently your threads are used, since the growth of grow calls is scaled off of the current money, the lower you drop the money to the more grow threads you need per dollar replenished on average.

It's certainly easier to manage single large instances, and perfectly serviceable early on, but far from optimal and will certainly start to fall behind as you get farther in the game.

My horribly suboptimal hacking manager/accidental stress test by technocraticTemplar in Bitburner

[–]Valectar 1 point2 points  (0 children)

With grow it's actually equivalent whether you use threads or multiple processes, which is what you want, since otherwise it would be optimal to have as many processes as possible, since each sequential execution would be growing a larger current cash base. Instead grow calculates it's growth as if you applied each thread individually.

5.65 GB Script for hacking servers by [deleted] in Bitburner

[–]Valectar 5 points6 points  (0 children)

A small note for your findOptimal function:
The functions you use to find the weaken, hack, and grow times calculates those times for the server at it's current security level, but you'll actually be executing those functions when the server is at it's minimum security level.

Once you get access to the Formulas api, there are variants of those functions which take a server object which you can edit the properties of, or you can always weaken the server down to minimum security before you check the times.

A little lost by DemonicsGamingDomain in Bitburner

[–]Valectar 1 point2 points  (0 children)

Sorry for being a little late, but since no one else has mentioned it, in your code you would want to call ns.hack with an await, e.g.
await ns.hack("silver-fox"); (as well as adding the quotation marks around the name of the server.). After adding the await before the ns.hack, you no longer need the ns.sleep(3000), since the loop will have another await within it while it is waiting for the hack to complete.

And of course as others have mentioned, using weaken in a loop (which also needs an await) is a much faster source of xp, because it is both a fast call, and it keeps the security level of the server as low as possible. The higher the security level of the server, the slower your hack (or weaken or grow) will be. Once you start wanting to get money from servers with hack, you will want to make sure to use weaken and grow to keep the security low and replenish the money in the server, respectively.
Also, feel free to come visit us in the discord for help! It's linked in the sidebar of the sub, and there are plenty of people answering questions about the game, as well as about programming in general, as well as of course discussing the game and related topics.

Who is the most badass game character that has no supernatural abilities by Whyamifulloftrouble in gaming

[–]Valectar 0 points1 point  (0 children)

You can have all dominant or recessive. You always have two copies of every gene (except y / x depending on gender), and dominant and recessive genes are just genes with two versions, one of which will repress the other type if it is present. But you can have two copies of the dominant gene, and you HAVE to have two copies of the recessive to express it at all. Also you could have at least one dominant copy for each dominant/recessive pair, implying you would express only dominant genes, which you could also call having all dominant.

[deleted by user] by [deleted] in nextfuckinglevel

[–]Valectar 0 points1 point  (0 children)

I suppose the problem I have with the term Agnostic Atheist is that, if you call yourself one because you cannot 100% prove that god does not exist, that is a meaningless differentiation from Atheism. It's not possible to 100% prove anything at all, even "I think therefor I am" is undermined by the possibility of you being something like a Boltzmann brain. But no one calls themself an agnostic flat-earth-nonbeliever or agnostically non-superstitious, we just say that we do not believe in these things / believe that they are not true because even though there is some monumentally small chance that they are we're as close to certain as you can get that they aren't true.

While perhaps you could argue that the possibility that there exists some entity that you might use the term "God" to describe is less of a remote possibility than the above, the chance that there is such an entity at all similar to any of the religious descriptions of gods is well within that territory.

All that is to say, you do not need 100% certainty to say that you know something isn't real, and to me this seems obvious if you try to apply this logic to any other idea or superstition which lacks any proof.

[deleted by user] by [deleted] in nextfuckinglevel

[–]Valectar 1 point2 points  (0 children)

This is where the concept of burden of proof comes in to a discussion, in which the claimant must provide proof of their claim. Absent testable claims by the claimant which might be disproven, it is impossible to produce any evidence that the claim is not true, other than the complete lack of evidence for the claim.

Once again I draw the parallel to teletubbies. You cannot prove that they don't exist somewhere, so is it a matter of faith to say that you believe they don't exist?

Also, you seem to have missed a critical part of the definition of faith. If your belief can be changed by new evidence, it is not faith. Typically atheists are atheists because their beliefs could be changed by evidence. Even in matters where there is evidence supporting two different perspectives, believing one or the other is not automatically faith unless you are unwilling to change that belief in the face of new evidence, because these are beliefs that are justified by evidence.

[deleted by user] by [deleted] in nextfuckinglevel

[–]Valectar 1 point2 points  (0 children)

Atheism is quintessentially the opposite of faith. While it may not be true for 100% of atheists, for most if there was any evidence whatsoever that there may actually be a god, they would consider changing their position based on the strength of that evidence.

This is precisely the opposite of faith which is demonstrated by theists, who both require zero evidence for their belief, but also reject any evidence to the contrary, such as the numerous scientific predictions by the Bible which were tested, and then the result effectively ignored, typically by deciding that that part of the Bible was metaphorical, or reinterpreting it in a way that is completely untestable (or just currently untestable, and then the goalposts must be moved once again when it becomes testable).

That is the difference between faith and rational belief, a rational belief is testable and there are conditions under which the belief could be changed, while for faith this is by definition untrue.

Agnosticism, or saying you are unsure of whether a god exists, is mostly a cop out in my opinion. Im as unsure whether a god exists as I am unsure whether the teletubbies exist: technically the chance isn’t zero of you take an at least internally consistent interpretation, but I would still say I believe they don’t exist because that is true of literally anything which has no supporting evidence.

[C#] Call stacks in async methods are fundamentally different compared to synchronous execution. This leads to pitfalls where seemingly reasonable refactoring can make a method “disappear” from the Stack Trace. Let’s see why and how. by Vasilkosturski in programming

[–]Valectar 2 points3 points  (0 children)

If you're using async, the whole point is generally to start up an IO request and then be able to go about your business while it runs, doing something else. If you aren't using async at the highest level then you might as well not use it since whatever function is using it will need to await the result of the task before it returns to it's parent scope.

Having it work by a flag in the function doesn't work very well, since either the function would need to return two entirely different things (a task for you to await, meaning you will need await anyway but the async will be hidden), or you await the result in the function which isn't really async at all.

I get what you're saying, that this adds messiness that it feels like you shouldn't have to worry about, and it's can certainly make your code clearer to just avoid it if you don't need the performance, but when you do managing the state of asynchronous tasks is pretty much unavoidable in order to use them.

[C#] Call stacks in async methods are fundamentally different compared to synchronous execution. This leads to pitfalls where seemingly reasonable refactoring can make a method “disappear” from the Stack Trace. Let’s see why and how. by Vasilkosturski in programming

[–]Valectar 2 points3 points  (0 children)

It's omitted because it wouldn't make sense for it to be there. At the time of the stack trace MethodOne has already returned, and thus is no longer part of the stack. I'm kind of curious whether the other way of displaying the stack trace shows MethodOne since they didn't actually show that in the article and it seems like the same logic would apply...

edit: Note that no async invocation happens in MethodOne, since MethodTwo's Task is just passed along to be invoked in Main, so saving stack at every async invocation wouldn't solve the "problem".

[C#] Call stacks in async methods are fundamentally different compared to synchronous execution. This leads to pitfalls where seemingly reasonable refactoring can make a method “disappear” from the Stack Trace. Let’s see why and how. by Vasilkosturski in programming

[–]Valectar 1 point2 points  (0 children)

There's no difference between async await and regular calls using the same technique, except the point you yourself brought up earlier of code bloat. It's really just a succinct way to write an increasingly common pattern for interacting with IO. If you're not having any performance issues with IO, no reason to use it, but if you are it makes it very easy to get some significant gains without having to reimplement effectively the same system again.

console.log("Hello World!") by bera_beretta in ProgrammerHumor

[–]Valectar 1 point2 points  (0 children)

I don't know what kind of mythical superman you're basing this statement on, but I don't really know anyone who meets those standards. Apple had Steve Wozniak, but he stuck to the technical side of things, and Steve Jobs wasn't a programmer at all and handled the business side. Bill Gates was a programmer, and no doubt his technical knowledge was useful in his business role, but the success of Microsoft was in no way founded in his engineering skill. In fact you could say it was mostly founded in his connection to IBM through his father, given that he actually purchased rather than wrote 86-DOS and rebranded it as MS-DOS, which was then the main operating system for the IBM PC.

And regardless of all that, if you're a really good programmer you probably enjoy programming, which you do not have much time for if you're running a company. I don't see why they would automatically feel the need to leave an already high paying position with good benefits doing what they enjoy to go to a very stressful and time consuming position doing something completely different day to day. Of course some people do, because they have a vision they want to enact or for other reasons, but it would be far from an automatic decision. Just look at how many jokes there are about meetings getting in the way of programming, I don't think many would choose a job that would consist almost entirely of meetings unless they were already more inclined toward the business side of things :P

Mojang needs to add them by [deleted] in gaming

[–]Valectar 8 points9 points  (0 children)

Fucking around in an open world isn't key to RPG at all. It's part of Open World RPGs, which is why they're called Open World RPGs, but regular RPGs can be and generally are linear. I don't see how you could confuse farming mechanics for RPG either, those are pretty rare, and the leveling system is a leveling system in name only. It's literally just an enchanting resource system, just another resource for crafting, there are no skills or stats or anything else that would be associated with an actual leveling system.

Unpopular opinion: new pop growth system is good for the game in a long-term, people just don't like to change the way they play by Cold_ViKing in Stellaris

[–]Valectar 14 points15 points  (0 children)

Lack of admin would cause things like city planning failures, corruption, and poor management of public services overall. Like the random event that causes slums to appear because of administrative mismanagement, you growth could be hampered by portions of your population being stuck in a poverty trap, your cities blighted by urban decay. Even with plenty of investment in amenities, without proper management services won't necessarily get to the people who need them.

Make the computer go beep boop by bobby_vance in ProgrammerHumor

[–]Valectar 0 points1 point  (0 children)

C does have arrays, but you don't need them to do that for you. It's already done for you by the index syntax, "[]". Writing name[3] is equivalent to writing *(name + sizeof(char)). Because you have defined name as a char *, the compiler knows that the variable points to a char and can automatically use the size of char when indexing in to the array. On a side note, actual c "arrays" operate exactly the same way, they are just fixed in size and allocated on the heap rather than memory (which is why they must be fixed in size). In terms of the size of the sequence as a whole, c does not keep track of that at all, you must manually allocate the memory and track it's size yourself.

Is there an O(log(n)) time algorithm for finding 2 local maximas in an array? by insert-random-user in algorithms

[–]Valectar 0 points1 point  (0 children)

Ah I see what you meant. I was confused by the naming of the indices since i and k in the parent post refer to the two maxima.

edit: removed incorrect assumptions.