Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Hammerite posted:

Despite working with async code in the past, I often find it difficult to wrap my head around it and I'm sure others do too. Could you help spread the knowledge by explaining why this code fails to do what the author intended it to do, and how you would go about fixing it (if you had to content yourself with just putting a bandaid on it?)

As the comment implies, the method is supposed to delay disposal until the background stuff is finished, with a maximum wait of 10 seconds, checking every 1 second. There are many ways to achieve this, with plenty that could be described as horrible and plenty that would be fine. But his code doesn't even achieve the stated goal - Task.Run just fires off an async task, it doesn't wait for it to finish, so that code will just flow on straight out of the DoDispose method, return to the Dispose method, and then flow on out of that, meaning the disposal has not been deferred at all.

It's not clear from the code, admittedly, but the Entity Framework context is involved here and is being disposed while still in use because of this code. The lifetime of the context is tied to the lifetime of the class that owns this code.

(The real coding horror to be honest is how overly complex this code is for what its doing, but I can't post the whole source code here).

putin is a cunt fucked around with this message at 01:24 on Jan 22, 2020

Adbot
ADBOT LOVES YOU

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

a hot gujju bhabhi posted:

As the comment implies, the method is supposed to delay disposal until the background stuff is finished, with a maximum wait of 10 seconds, checking every 1 second. There are many ways to achieve this, with plenty that could be described as horrible and plenty that would be fine. But his code doesn't even achieve the stated goal - Task.Run just fires off an async task, it doesn't wait for it to finish, so that code will just flow on straight out of the DoDispose method, return to the Dispose method, and then flow on out of that, meaning the disposal has not been deferred at all.

It looks like they thought async would create some sort of yielding coroutine, to return to some other context while waiting

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Kilson posted:

It looks like they thought async would create some sort of yielding coroutine, to return to some other context while waiting

That's what I think too. They've done it in a few other places as well that I've had to fix, but this one was in a very critical part of the code.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Volmarias posted:

I'm not a c# dev, but seems like

- This doesn't need to be recursive, it should absolutely be iterative
- CacheService should have an async function that completes when the background refresh is no longer in progress
- Task.Run returns immediately, although it's not clear if the author wanted the waiting to happen on another thread or not so that might be ok, but recursively making a new thread each time is gross

Edit:
Assuming we can't do #2 and #3 is expected behavior, seems like we can do slightly better with

If #3 is expected behavior then the developer also misunderstood the IDisposable API, as it's explicitly a synchronous interface and everything must be cleaned up before returning from the Dispose() method. There's a slightly different IAsyncDisposable interface for async cleanup.

Ruzihm
Aug 11, 2010

Group up and push mid, proletariat!


a hot gujju bhabhi posted:

As the comment implies, the method is supposed to delay disposal until the background stuff is finished, with a maximum wait of 10 seconds, checking every 1 second. There are many ways to achieve this, with plenty that could be described as horrible and plenty that would be fine. But his code doesn't even achieve the stated goal - Task.Run just fires off an async task, it doesn't wait for it to finish, so that code will just flow on straight out of the DoDispose method, return to the Dispose method, and then flow on out of that, meaning the disposal has not been deferred at all.

I must be misreading something. How can flow go from running Task.Run to going "out" into running Scope.Dispose, when one is in an if and the other is in an else, and the only recursion occurs from the if block?

When I first read it, the horror I saw was that it should only need to spawn the one thread which could just be iterative. And from what Plorkyeran said, it should implement IAsyncDisposable and have the method be DisposeAsync.

Is it supposed to Dispose when 10 seconds have elapsed regardless of the refresh's progress? If not, then I think Volmarias nailed it especially with the if at the end.

Ruzihm fucked around with this message at 16:04 on Jan 22, 2020

Jen heir rick
Aug 4, 2004
when a woman says something's not funny, you better not laugh your ass off

Ruzihm posted:

I must be misreading something. How can flow go from running Task.Run to going "out" into running Scope.Dispose, when one is in an if and the other is in an else, and the only recursion occurs from the if block?

When I first read it, the horror I saw was that it should only need to spawn the one thread which could just be iterative. And from what Plorkyeran said, it should implement IAsyncDisposable and have the method be DisposeAsync.

Is it supposed to Dispose when 10 seconds have elapsed regardless of the refresh's progress? If not, then I think Volmarias nailed it especially with the if at the end.

I think the problem is that the code that calls dispose doesn’t know to wait for the task to complete. Once dispose is called the runtime is free to garbage collect the object as well as anything it references. So you end up with a race condition.

Ruzihm
Aug 11, 2010

Group up and push mid, proletariat!


Jen heir rick posted:

I think the problem is that the code that calls dispose doesn’t know to wait for the task to complete. Once dispose is called the runtime is free to garbage collect the object as well as anything it references. So you end up with a race condition.

Ooh, ok. Gotcha.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Volmarias posted:

- CacheService should have an async function that completes when the background refresh is no longer in progress

That's how it's implemented internally - that bool property is just an accessor that checks the IsCompleted flag on a private Task inside the CacheService.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Jen heir rick posted:

I think the problem is that the code that calls dispose doesn’t know to wait for the task to complete. Once dispose is called the runtime is free to garbage collect the object as well as anything it references. So you end up with a race condition.

This was my interpretation - but some of the replies in the .NET thread are making me think I might actually be the coding horror :(

reversefungi
Nov 27, 2003

Master of the high hat!
Would this qualify as a horror? I was looking at a company's careers page and noticed an ad for a front-end developer. The main language requirement was C++ which seemed strange. Investigating further, it looks like their entire front-end is built in JUCE. Given my (very limited) exposure to C++, trying to write a front-end in C++ sounds like all kinds of horrible unpleasantness.

Volguus
Mar 3, 2009

The Dark Wind posted:

Would this qualify as a horror? I was looking at a company's careers page and noticed an ad for a front-end developer. The main language requirement was C++ which seemed strange. Investigating further, it looks like their entire front-end is built in JUCE. Given my (very limited) exposure to C++, trying to write a front-end in C++ sounds like all kinds of horrible unpleasantness.

Why do you think that? C++ would provide a native, efficient desktop application (coding horrors notwithstanding). In what language/platform do you think a front-end should be written in?

Carbon dioxide
Oct 9, 2012

I guess everything is "web" nowadays and because of that, to make a normal desktop app they just wrap a shitload of css and javascript in electron and call it a day.

Traditional desktop GUI applications seem... well, not rarer, but I don't see nearly as much job vacancies looking for people with knowledge of how to make those. But perhaps that's just my bubble, I'm not sure.

Tei
Feb 19, 2011

repiv posted:

The developer of classic indie game VVVVVV just released its source code to celebrate its 10 year anniversary

https://github.com/TerryCavanagh/VVVVVV/blob/master/desktop_version/src/Game.cpp

tag yourself i'm the 4000 line switch statement that appears to contain most of the gameplay logic

actually no i'm the build instructions urging you to only using debug builds because optimizations break the game

how can you do this and not put half of that in a function or a separate file, if only where for the convenience.. and harggggg.. using numers instead of giving a name, even if is INTERMISION_8A

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

The Dark Wind posted:

Would this qualify as a horror? I was looking at a company's careers page and noticed an ad for a front-end developer. The main language requirement was C++ which seemed strange. Investigating further, it looks like their entire front-end is built in JUCE. Given my (very limited) exposure to C++, trying to write a front-end in C++ sounds like all kinds of horrible unpleasantness.

my, what have the kids come to these days

zergstain
Dec 15, 2005

Hammerite posted:

Despite working with async code in the past, I often find it difficult to wrap my head around it and I'm sure others do too. Could you help spread the knowledge by explaining why this code fails to do what the author intended it to do, and how you would go about fixing it (if you had to content yourself with just putting a bandaid on it?)

A bit late, but if I understand async properly, DoDispose() will return immediately after creating a new thread that will call DoDispose with retryCount + 1 after 1 second (I assume Delay is in ms). The process of waiting 1 second and calling DoDispose continues recursively until retryCount == 10 or BackgroundRefreshInProgress == false.

I don't actually know .NET at all, but I'm just going to assume that chain-spawning 10 threads is the dumbest possible way to do this, and something like Volmarias' solution is much better, although their's appears to just give up after 10 seconds, while the original looks like it just calls Scope.Dispose() whether the background refresh is done or not.

I may have messed up my reasoning somewhere because the original bug was an early dispose, or maybe 10 seconds sometimes isn't long enough.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Volguus posted:

Why do you think that? C++ would provide a native, efficient desktop application (coding horrors notwithstanding). In what language/platform do you think a front-end should be written in?

Yeah, the mere fact of using C++ isn't enough to assume it's a horror. I don't know much about JUCE, but what little I know doesn't make me automatically assume it's a horror either.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


The Dark Wind posted:

Would this qualify as a horror? I was looking at a company's careers page and noticed an ad for a front-end developer. The main language requirement was C++ which seemed strange. Investigating further, it looks like their entire front-end is built in JUCE. Given my (very limited) exposure to C++, trying to write a front-end in C++ sounds like all kinds of horrible unpleasantness.

Between college and grad school I spent some time doing what would now be considered front-end development in C++. It was fine for what it was. A lot of the complexity in front-end is just inherent to making UIs, and honestly having a statically type-checked language cuts down on the number of bugs you can have. I can definitely see some issues for someone whose only programming experience is in JavaScript, but otherwise this doesn't seem that bad unless JUCE is inherently horrible.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

ultrafilter posted:

Between college and grad school I spent some time doing what would now be considered front-end development in C++. It was fine for what it was. A lot of the complexity in front-end is just inherent to making UIs, and honestly having a statically type-checked language cuts down on the number of bugs you can have. I can definitely see some issues for someone whose only programming experience is in JavaScript, but otherwise this doesn't seem that bad unless JUCE is inherently horrible.

Well it's not just a choice between C++ and JavaScript though. There's a middle ground of other more "friendly" statically typed languages that you can use. But yeah, C++ is still totally fine for a front-end and not a horror.

Xarn
Jun 26, 2015
If your computation core is C++ and want to provide native app, there is no reason to use any of the "in-between" languages. Either bolt on more C++ or go hard for typescript and ""modern"" ui frameworks (lol)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I don't know anything about this JUCE, but my experience of frontends in C++ is MFC, so I'm extremely suspicious of it.

My inclination is that C++ is for when you have to write stuff that uses the computer's resources very efficiently, which is why it's good for writing number-crunching routines that run a million times a second. However front-end stuff tends to be wiring up routines that run whenever e.g. the user clicks a button, which does not happen a million times a second and it really does not matter whether it uses the computer's resources at all efficiently. And doing things in C++ is cumbersome because you don't have a lot of time-saving conveniences built in to the language.

As someone else said, your choices are not limited to the two extremes of "type-safe but cumbersome" C++ or "anything goes" HTML+JavaScript.

e: For clarity, the prototype I have in mind for a framework that does have "time-saving conveniences built in" is WPF.

Hammerite fucked around with this message at 11:22 on Jan 23, 2020

Tei
Feb 19, 2011

C++ is awesome

Boomers - desktop apps
GenerationX and millenials - web apps

susan b buffering
Nov 14, 2016

JUCE is geared towards audio applications, so it’s a strange choice if they aren’t doing anything audio-related, but there’s probably nothing wrong with using just the UI bits.

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:

Hammerite posted:

it really does not matter whether it uses the computer's resources at all efficiently

That attitude is why applications from 20 years ago feel more responsive than todays "we need to peg a core for 500ms to open a context menu" applications. :colbert:

nielsm
Jun 1, 2009



Also with C++ for web applications, you can have lightning fast HTML templates. And if you want to be hip, you could implement your data validation rules as a library that can compile to WASM and include that straight in the browser.

Tei
Feb 19, 2011

I am newbie here in SA so I had not idea about this

https://www.youtube.com/watch?v=UCgoxQCf5Jg

I am speechless and a bit scared now

Tei fucked around with this message at 13:47 on Jan 23, 2020

OddObserver
Apr 3, 2009

Hammerite posted:

I don't know anything about this JUCE, but my experience of frontends in C++ is MFC, so I'm extremely suspicious of it.


C++ has plenty of its own problems (*cough* memory safety *cough), but IIRC MFC is just an awful library.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Antigravitas posted:

That attitude is why applications from 20 years ago feel more responsive than todays "we need to peg a core for 500ms to open a context menu" applications. :colbert:

It is possible to take any sensible maxim to ridiculous extremes. It is not necessary to worry about efficiency to the nth degree for an operation like "open a context menu" that occurs, from the computer's perspective, once in an ice age. That does not mean you should be content if your application is so ridiculously inefficient as in your example.

Basically, there are 3 qualitative levels of speed. Super-fast, fast-enough, and not-fast-enough. It is worth hitting the "fast-enough" target. It is not worth stretching to hit "super-fast" - not for UI code. Using a relatively low-level language like C++ is worthwhile to make number-crunching code super-fast, but is not necessary to make UI code fast-enough. You can achieve that with other technologies with less effort.

I am sure that the MFC code I maintain written in C++ is orders of magnitude faster than the UI code in the newer WPF apps I write and maintain. I am equally certain that the grotty MFC code is not worth that speed-up, which is not noticeable to a user.

FlapYoJacks
Feb 12, 2009

OddObserver posted:

C++ has plenty of its own problems (*cough* memory safety *cough), but IIRC MFC is just an awful library.

Just lol if you manage your own memory in C++ ITYOOL 2020.

Absurd Alhazred
Mar 27, 2010

by Athanatos

ratbert90 posted:

Just lol if you manage your own memory in C++ ITYOOL 2020.

Yeah, they're called std::unique_ptr and std::shared_ptr, learn them!

Also there are a lot of GUI frameworks for C++, including the one we use at work, Dear ImGui, which is actually pretty straightforward and I can't recommend it enough. It does require you to run your own UI loop instead of relying on callbacks, but that surprisingly just streamlines everything.

reversefungi
Nov 27, 2003

Master of the high hat!
Thanks goons, I'm still a dumb newbie who looks at C++ and gets very intimidated, so the thought of trying to do front-end web development work (which is already a pain) in C++ sounded like an extra-challenge. I guess if you're already comfortable with C++, it's a much different story.

FlapYoJacks
Feb 12, 2009

The Dark Wind posted:

Thanks goons, I'm still a dumb newbie who looks at C++ and gets very intimidated, so the thought of trying to do front-end web development work (which is already a pain) in C++ sounded like an extra-challenge. I guess if you're already comfortable with C++, it's a much different swetory.

Nobody wants to do front-end work in C++ unless it's webkit or QT.

I think Springboot is what most companies use if they're Java based, and Django/Flask if their Python based.

feedmegin
Jul 30, 2008

OddObserver posted:

C++ has plenty of its own problems (*cough* memory safety *cough), but IIRC MFC is just an awful library.

This. Its ancient and was basically designed by 90s Microsoft interns who had just read C++ For Dummies. It was bad even 20 years ago.

Qt is C++ and is used for all sorts of stuff, though.

Tei
Feb 19, 2011

I have really good memories of C++
reading about it make me feel like returning to it

It was a fun programming language but memory related bugs where nasty

FlapYoJacks
Feb 12, 2009

Tei posted:

I have really good memories of C++
reading about it make me feel like returning to it

It was a fun programming language but memory related bugs where nasty

Except in some very rare cases, with C++ >= 14 you shouldn't manage memory.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

The Dark Wind posted:

Thanks goons, I'm still a dumb newbie who looks at C++ and gets very intimidated, so the thought of trying to do front-end web development work (which is already a pain) in C++ sounded like an extra-challenge. I guess if you're already comfortable with C++, it's a much different story.

Are you sure it's web development?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Yeah, I have no idea if this is accurate, but my gut tells me that doing frontend native UI in C++ is a completely different beast from doing frontend web UI in C++.

Bongo Bill
Jan 17, 2012

I like to describe the layout of a UI using HTML and CSS, but only browsers, with all their attendant overhead, have this capability.

FlapYoJacks
Feb 12, 2009
My team lead just tried to tell me that you shouldn't have the expectation of who get's what tickets beforehand before they get assigned a point value. :psyduck:

CPColin
Sep 9, 2003

Big ol' smile.
I mean, for a certain value of "shouldn't," that's kind of true. On an ideal team, everybody should be able to handle every ticket and everybody should come to similar values when estimating their points. In the real world, yeah, you're pretty sure the team member who implemented Feature X is going to have a couple of sprints where they get assigned all the Feature X bugs.

Adbot
ADBOT LOVES YOU

Tei
Feb 19, 2011

ratbert90 posted:

My team lead just tried to tell me that you shouldn't have the expectation of who get's what tickets beforehand before they get assigned a point value. :psyduck:

I don't know what is this point value system for? care to elaborate or point me somewhere?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply