There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

EisFrei , in Sleep() at home

Ah yes. The speedup-loop.
thedailywtf.com/articles/The-Speedup-Loop

tryptaminev ,

This is brilliant.

Aceticon , in Bug Fixing

Well, duh! You need to use the right incantations!

DeepGradientAscent ,
@DeepGradientAscent@programming.dev avatar

All praise the Omnissiah, so on, and so forth.

TurboHarbinger ,

Something something motive force.

quantenzitrone , in Bug Fixing

i sometimes do that so i can inspect the error messages on a cleared terminal

winky9827b ,

Sometimes I forget what I was looking for and have to restart the mental loop when doing this.

PoolloverNathan , in Bug Fixing

One of my old programs produces a broken build unless you then compile it again.

mindbleach ,

Some code has bugs.

Some code has ghosts.

rimjob_rainer , in GTA 5 Java Coffee shop

Why does someone come up with java code for an in-game coffeeshop and then make an obvious mistake? Or is that on purpose and they are trolling?

Blackmist , in Bug Fixing

Yeah, but sometimes it works.

noddy ,

Good luck figuring out why it sometimes doesn’t work 🙃

CanadaPlus ,

Mmm, race conditions, just like mama used to make.

Aceticon ,

It’s even worse then: that means it’s probably a race condition and do you really want to run the risk of having it randomly fail in Production or during an important presentation? Also race conditions generally are way harder to figure out and fix that the more “reliable” kind of bug.

dev_null ,

Or it was an issue with code generation, or something in the environment changed.

Octopus1348 ,
@Octopus1348@lemy.lol avatar

There was that kind of bug in Linux and a person restarted it idk how much (iirc around 2k times) just to debug it.

wewlad ,

We call this sort of test “fuzzy”. If it’s really bad they call it by my own personal identifier of “unstable”.

KairuByte ,
@KairuByte@lemmy.dbzer0.com avatar

Legit happens without a race condition if you’ve improperly linked libraries that need to be built in a specific order. I’ve seen more than one solution that needed to be run multiple times, or built project by project, in order to work.

abraxas ,

Isn’t that the definition of a race condition, though? In this case, the builds are racing and your success is tied to the builds happening to happen at the right times.

Or do you mean “builds 1 and 2 kick off at the same time, but build 1 fails unless build 2 is done. If you run it twice, build 2 does “no change” and you’re fine”?

Then that’s legit.

KairuByte ,
@KairuByte@lemmy.dbzer0.com avatar

Yup, it’s that second one. 0% chance of success until all dependencies are built, then the final run has a 100% chance to work.

crushyerbones ,

This is 100% valid when dealing with code generation sometimes and I hate it

jerrythegenius , in Bug Fixing
@jerrythegenius@lemmy.world avatar

I actually did this earlier today

Schal330 ,

I’ve only recently joined the dev world and I saw this post in the morning. Late this afternoon I’m doing a deployment that fails, couldn’t determine the cause as I’m a noob, before bothering a more senior dev for help I run it again… It worked.

gravitas_deficiency , in Bug Fixing

<span style="color:#323232;">======== 37/37 tests passing ========
</span>
OsrsNeedsF2P ,

That’s when the real debug session begins

lorty ,
@lorty@lemmy.ml avatar

Great time to find out your tests are useless!

gravitas_deficiency ,

They’re not completely useless. They’re conditionally useless, and we don’t know the condition yet.

CanadaPlus , (edited )

So how do you write a good test? It’s like you have to account for unknown unknowns, and I don’t really have a good theory for doing that.

Right now, I usually end up writing tests after the code is broken, and most of them pass because they make the same mistakes as my original code.

Theharpyeagle ,

For unit tests, you should know the input and expected output from the start. Really responsible devs write the unit tests first, because you should know what you’re going to put in and what you’ll get out before you start writing anything. If you find yourself making the same mistakes in your tests as you do your code, you might be trying to do too much logic in the test itself. Consider moving that logic to its own testable class, or doing a one-time generation of a static set of input/output values to test instead of making them on the fly.

How granular your tests should be is a matter of constant debate, but generally I believe that different file/class = different test. If I have utility method B that’s called in method A, I generally test A in a way that ensures the function of B is done correctly instead of writing two different tests. If A relies on a method from another class, that gets mocked out and tested separately. If B’s code is suitably complex to warrant an individual test, I’d consider moving to to its own class.

If you have a super simple method (e.g. an API endpoint method that only fetches data from another class), or something that talks with an external resource (filesystem, database, API, etc.) it’s probably not worth writing a unit test for. Just make sure it’s covered in an integration test.

Perhaps most importantly, if you’re having a lot of trouble testing your code, think about if it’s the tests or the code that is the problem. Are your classes too tightly coupled? Are your external access methods trying to perform complex logic with fetched data? Are you doing too much work in a single function? Look into some antipatterns for the language/framework you’re using and make sure you’re not falling into any pitfalls. Don’t make your tests contort to fit your code, make your code easy to test.

If ever you feel lost, remember the words of the great Testivus.

CanadaPlus ,

First off, thanks for the help!

Really responsible devs write the unit tests first, because you should know what you’re going to put in and what you’ll get out before you start writing anything.

I’ve obviously heard the general concept, but this is actually pretty helpful, now that I’m thinking about it a bit more.

I’ve written pretty mathy stuff for the most part, and a function might return an appropriately sized vector containing what looks like the right numbers to the naked eye, but which is actually wrong in some high-dimensional way. Since I haven’t even thought of whatever way it’s gone wrong, I can’t very well test for it. I suppose what I could do is come up with a few properties the correct result should have, unrelated to the actual use of it, and then test them and hope one fails. It might take a lot of extra time, but maybe it’s worth it.

How do you deal with side effects, if what you’re doing involves them?

Theharpyeagle ,

For your vector issue, I’d go the route of some static examples if possible. Do you have a way to manually work out the answer that your code is trying to achieve?

For side effects, that may indicate what I referred to as tightly coupled code. Could you give an example of what you mean by “side effect”?

CanadaPlus , (edited )

For your vector issue, I’d go the route of some static examples if possible. Do you have a way to manually work out the answer that your code is trying to achieve?

Not necessarily. In this scenario I’d imagine it’s a series of numbers as opposed to something more human-friendly exactly because there’s internal complexity that’s important but hard to manually survey, let alone generate. If you’ve worked with GANs at all, maybe it’s a point in a latent space.

For side effects, that may indicate what I referred to as tightly coupled code. Could you give an example of what you mean by “side effect”?

I mean it in the standard functional language way, if you’re familiar. There’s an operation that happens at some step of an algorithm, and it changes a data structure which is referred to or updated at another step. Sometimes you can’t really avoid it, because the problem itself has an interconnection like that.

A sorting algorithm example, if that doesn't make this too complicated.Concurrency it’s pretty much guaranteed to do it, so let’s say we’re trying to implement some sort of bespoke sorting algorithm, where each compare is large and complex enough we have bugs, and which runs in multiple threads. If threads are interfering with each other in this program, how do you test for that? The whole thing won’t give expected results, obviously, but another unsorted array or a failure to terminate doesn’t tell you much. Each compare and each swap might look correct at first, and give properly typed results. Let’s assume that each thread might traverse to anywhere in the array, so you can’t just check when they’re overlapping.

Aria , in Bug Fixing

Somehow higher than 0% success rate.

Peafield , in Bug Fixing

The first is a surprise; the second is testing.

Pantrygheist , in Bug Fixing

That’s step zero: rule out black magic

DragonTypeWyvern ,

That feeling when it is, in fact, computer ghosts.

embed_me ,
@embed_me@programming.dev avatar

Those damn cosmic rays flipping my bits

blanketswithsmallpox ,

Please tell me you look skyward, shake your fist and yell damn you!!!

CanadaPlus ,

I wonder if there’s an available OS that parity checks every operation, analogous to what’s planned for Quantum computers.

Danitos ,

Unrelated, but the other day I read that the main computer for core calculation in Fukushima’s nuclear plant used to run a very old CPU with 4 cores. All calculations are done in each core, and the result must be exactly the same. If one of them was different, they knew there was a bit flip, and can discard that one calculation for that one core.

CanadaPlus , (edited )

Interesting. I wonder why they didn’t just move it to somewhere with less radiation? And clearly, they have another more trustworthy machine doing the checking somehow. A self-correcting OS would have to parity check it’s parity checks somehow, which I’m sure is possible, but would be kind of novel.

In a really ugly environment, you might have to abandon semiconductors entirely, and go back to vacuum as the magical medium, since it’s radiation proof (false vacuum apocalypse aside). You could make a nuvistor integrated “chip” which could do the same stuff; the biggest challenge would be maintaining enough emissions from the tiny and quickly-cooling cathodes.

nieceandtows , in Bug Fixing

Just had that happen to me today. Setup logging statements and reran the job, and it ran successfully.

TurtleTourParty ,

I’ve had that happen, the logging statements stopped a race condition. After I removed them it came back…

Hupf ,

Thank you for playing Wing Commander!

Fixbeat , in Bug Fixing

Got to make sure it’s not one of those phantom failures.

xor , in Bug Fixing

could be a race condition

vamputer ,
@vamputer@infosec.pub avatar

Hmm…you may be right. I’ll get my Hispanic friend to run it and see if he gets the same result.

aiden ,

It works on my machine

gaston1592 ,

ok, then we ship your machine.

DeepGradientAscent ,
@DeepGradientAscent@programming.dev avatar

I, too, enjoy containers.

asg101 , in Bug Fixing

“Works in my environment.”

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines