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
Riot Bimbo
Dec 28, 2006


epalm posted:

There's definitely a lot of mediocre (or just outdated) material out there.

Are you learning just to learn, or are you working on a project? "Learning just to learn" is a bit like learning music notation without actually playing an instrument. I can learn what all these symbols mean, in depth, but unless I actually make some noises with an instrument (and fail a lot, and stick with it, and slowly get better) I'm not getting any meaningful work done.

I've been trying to set up just a personal page to put some domains I have parked to use. Earlier in December, I was working on making a guestbook, more or less just because I needed *something* and it felt like a good little project to start with, but I have next to no grounding in css/bootstrap, and just nabbing chunks of code from places seems clunky and not-good.

I have no idea what kind of project to set my mind on.

I've watched some Tim Corey stuff, i'll dive him further.

Adbot
ADBOT LOVES YOU

LongSack
Jan 17, 2003

redleader posted:

dapper is real good how dare you

My problem isn’t with Dapper or CM per se, it’s just that - and maybe it’s just me - if you’re using a tool like that when teaching, especially newcomers, then you’re not teaching MVVM, you’re teaching Caliburn Micro. I’ve never used Dapper, but in his examples it seems to rely a lot on dynamic which I find suspect (or maybe I’m misremembering)

raminasi
Jan 25, 2005

a last drink with no ice

LongSack posted:

My problem isn’t with Dapper or CM per se, it’s just that - and maybe it’s just me - if you’re using a tool like that when teaching, especially newcomers, then you’re not teaching MVVM, you’re teaching Caliburn Micro. I’ve never used Dapper, but in his examples it seems to rely a lot on dynamic which I find suspect (or maybe I’m misremembering)

You can use Dapper without touching dynamic and honestly using dynamic seems like it misses the point entirely. This doesn't sound like a Dapper problem.

LongSack
Jan 17, 2003

raminasi posted:

You can use Dapper without touching dynamic and honestly using dynamic seems like it misses the point entirely. This doesn't sound like a Dapper problem.

Ok, then I withdraw my objection to Dapper. My unease with Caliburn Micro stands.

Riot Bimbo
Dec 28, 2006


To be honest, I get really annoyed at stuff that recommends third party stuff when claiming to teach the basics. Like, thanks for teaching me *a* route, but I was looking for something a bit more fundamental, I guess. Even if that's harder, I don't really want those kinds of gaps in my knowledge base, where I need weird little crutches to do certain things going forward.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

God I love this language :fap:



And yeah, there's probably a bunch more formats I didn't know about. And I could have just googled a few well-tested regexes. But it's what hobby projects are for.

epswing
Nov 4, 2003

Soiled Meat

NihilCredo posted:

God I love this language :fap:

Is it typical to have type-related comments in F#? I see it more often in dynamically-typed languages, less so in statically-typed languages.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

epalm posted:

Is it typical to have type-related comments in F#? I see it more often in dynamically-typed languages, less so in statically-typed languages.

They're not real comments, they're the type "tooltips" inferred by the VSCode F# plugin. I just like having them prefixed with the comment slashes because I think it reads better.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Is pre-declaring the error like that just a style preference?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Munkeymon posted:

Is pre-declaring the error like that just a style preference?

Just DRY. I realized I was returning the same error on every unhappy path - "can't figure out this string" - so it made sense to eliminate the repetition. Would be more obvious if the error value was more complex, e.g. Error $"Video URL format not recognized: %O{uri}", which you would definitely not want to duplicate.

Mr Shiny Pants
Nov 12, 2012

NihilCredo posted:

Just DRY. I realized I was returning the same error on every unhappy path - "can't figure out this string" - so it made sense to eliminate the repetition. Would be more obvious if the error value was more complex, e.g. Error $"Video URL format not recognized: %O{uri}", which you would definitely not want to duplicate.

It is wonderful, the one thing I do wish it had is a catchall in the patternmatching when a couple of levels deep. When not handling something three levels deep with a catchall, take the one a couple of levels higher especially when they are essentially the same.

There are couple times in my code where I am just writing error handlers of type "Error string" and just put stuff in it to make the compiler happy.

I dunno, just a style thing I guess.

mystes
May 31, 2006

Mr Shiny Pants posted:

It is wonderful, the one thing I do wish it had is a catchall in the patternmatching when a couple of levels deep. When not handling something three levels deep with a catchall, take the one a couple of levels higher especially when they are essentially the same.

There are couple times in my code where I am just writing error handlers of type "Error string" and just put stuff in it to make the compiler happy.

I dunno, just a style thing I guess.
Maybe try to flatten the match expression by using a tuple with partial active patterns or something?

Mr Shiny Pants
Nov 12, 2012

mystes posted:

Maybe try to flatten the match expression by using a tuple with partial active patterns or something?

Railway Oriented is another approach, but sometimes it is just nice to write the whole match except for the "unhappy" path.

sausage king of Chicago
Jun 13, 2001
Does anyone follow any kind of design pattern when dealing with error handling? I've been tasked with reworking the error handling/messaging for one of our APIs at work, and then possibly have whatever pattern I use be used as a template for other APIs in our department. Haven't really heard of any error handling patterns before and googling isn't showing much, so not even sure if this is a thing.

rarbatrol
Apr 17, 2011

Hurt//maim//kill.

sausage king of Chicago posted:

Does anyone follow any kind of design pattern when dealing with error handling? I've been tasked with reworking the error handling/messaging for one of our APIs at work, and then possibly have whatever pattern I use be used as a template for other APIs in our department. Haven't really heard of any error handling patterns before and googling isn't showing much, so not even sure if this is a thing.

For a while I was on a project that involved ingesting data from one system to another, with a few intermediate data enrichment steps. We used the either monad to capture and accumulate errors for each step, where the "other" side of the either was whatever came out of each processing step, later used as input for the next processing step. It's nice because you accumulate the errors naturally step by step, and each step only applies to non-error records.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
Not really a design pattern but use Polly to create Policies for error handling and retry. You can start really simple and evolve your policies over time if needed.

sausage king of Chicago
Jun 13, 2001

Calidus posted:

Not really a design pattern but use Polly to create Policies for error handling and retry. You can start really simple and evolve your policies over time if needed.

Would this fit for my use case or would it be overkill? I just want to return detailed error messages when a bad request comes in - i.e "500 error - That user does not exist"

insta
Jan 28, 2009
:colbert: that's a 404

Xik
Mar 10, 2011

Dinosaur Gum
Every api I've worked on that didn't eventually turn into a flaming pile of garbage, had some sort of common reponse classes (or internal common library depending on size) and a bunch of accepted patterns for both internal and external error and message handling.

I might receive some hairy responses for saying this but the way Go returns Errors is actually sort of the pattern that I've always seen in apis and it works pretty well. The obvious major difference is you don't have to spray error object checking at every level of your app and libraries because .NET also has exceptions :v:.

The rough pattern is made up of a few decisions:
1. Decide on a common wrapper object and what error/meta data it contains.
2. Decide the cut off level in your stack where this wrapper is/isn't used.
3. Decide if your wrapper is safe for api consumers or you need a seperate mapping for the final response.

For 1. it's the easiest since you can just make it whatever you want, a trivial example might be:

code:
class InternalError
{
	int Code { get; set; }
	string Message { get; set; }
}

class InternalResponse<T>
{
	T Payload { get; set; } // Payload or data or whatever it is you are handling/returning. Some operations you might only care about the success and this will be null
	bool Success { get; set; }
	IList<InternalError> Errors { get; set; }
}
You can stuff it full of whatever meta data you want. Flags, messages, status codes, priorities, warnings etc basically whatever makes sense for your api, you'll have to maintain it and set it so maybe don't go too nuts.

2. Would usually be fairly simple to figure out. You wouldn't want to have every library/utility/helper/whatever to be aware of this object so it likely makes sense that it's usage ends where your fat logic or integration stuff goes. Maybe even the data layer if you have eloborate custom error messaging from other services that you want to pick apart and bubble up. For most things you'll still want to raise and catch exceptions, but at some layer you'll want to catch them and fill in this wrapper object.

3. Could be the most important part depending on what your api does and who the audience is. You'll probably want a little common mapper to transform this internal response into your actual public response. Probably at the controller level, transform internal errors into appropriate HTTP status codes on the response and have user friendly (and security conscious) error messages.

Calidus
Oct 31, 2011

Stand back I'm going to try science!

sausage king of Chicago posted:

Would this fit for my use case or would it be overkill? I just want to return detailed error messages when a bad request comes in - i.e "500 error - That user does not exist"

Oh yea, Polly is more for dealing with internal errors. It won’t really help you return meaningful error messages and error codes. I have used something similar to what Xik described.

Riot Bimbo
Dec 28, 2006




Aaaaaahhhh!!!! it's sorta working!!!!

The posts are fake, but the fact I was able to get the thing to pull the appropriate data from my database--- that I was able to configure any of this--- has been a small miracle. I had been pretty convinced my skill level just wasn't here yet, but I've only been using my own references and code as a resource, so this is kind of amazing for me.

Now, to make that awful looking form group actually work and submit data~

that part feels inconsequential, because getting to the screenshot has been painful as hell

epswing
Nov 4, 2003

Soiled Meat

Riot Bimbo posted:

Aaaaaahhhh!!!! it's sorta working!!!!

Nice, love that feeling.

Nostalgamus
Sep 28, 2010

I've been fiddling with async functions, and getting really confused.

Basically, I have an aspx page with a button. Clicking that button should run a call to a web service, which will usually take ~30min to run. The idea was to run this call asynchronously, i.e. start the function and return immediately, but that seems not to be working.

I'm using the auto-generated <FunctionName>Async() call from the web service (asmx file). It worked fine when testing with no input, the Completed event I attached correctly fired with an error message right away since the call had completed. Once I gave valid input, it starts running, and then basically makes the page hang until what I'm assuming is the timeout (about 5min).

At this point I started googling, and found some information that got me really confused. Apparently, using an *Async call is not asynchronous for that session? Instead it just return the thread to thread pool on the server - which I suppose is useful, but not what I'm looking for here. Debugging shows that the *Async() function call itself returns immediately, is it delaying the postback somehow?

mystes
May 31, 2006

Nostalgamus posted:

I've been fiddling with async functions, and getting really confused.

Basically, I have an aspx page with a button. Clicking that button should run a call to a web service, which will usually take ~30min to run. The idea was to run this call asynchronously, i.e. start the function and return immediately, but that seems not to be working.

I'm using the auto-generated <FunctionName>Async() call from the web service (asmx file). It worked fine when testing with no input, the Completed event I attached correctly fired with an error message right away since the call had completed. Once I gave valid input, it starts running, and then basically makes the page hang until what I'm assuming is the timeout (about 5min).

At this point I started googling, and found some information that got me really confused. Apparently, using an *Async call is not asynchronous for that session? Instead it just return the thread to thread pool on the server - which I suppose is useful, but not what I'm looking for here. Debugging shows that the *Async() function call itself returns immediately, is it delaying the postback somehow?
Uh, you're using await, right? If so, be aware that the whole point of awaiting an asynchronous function is that you want to resume the calling function when the result is obtained, so consider if that's what you really want to do here.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Nostalgamus posted:

I've been fiddling with async functions, and getting really confused.

Basically, I have an aspx page with a button. Clicking that button should run a call to a web service, which will usually take ~30min to run. The idea was to run this call asynchronously, i.e. start the function and return immediately, but that seems not to be working.

I'm using the auto-generated <FunctionName>Async() call from the web service (asmx file). It worked fine when testing with no input, the Completed event I attached correctly fired with an error message right away since the call had completed. Once I gave valid input, it starts running, and then basically makes the page hang until what I'm assuming is the timeout (about 5min).

At this point I started googling, and found some information that got me really confused. Apparently, using an *Async call is not asynchronous for that session? Instead it just return the thread to thread pool on the server - which I suppose is useful, but not what I'm looking for here. Debugging shows that the *Async() function call itself returns immediately, is it delaying the postback somehow?

Your web service shouldn't take 30 minutes to run without returning a result. You shouldn't start a process in a web application that takes 30 minutes to run, ever, synchronously or asynchronously.

mystes
May 31, 2006

If it's a rest api you need to have the api call return and then either the client will need to keep making calls to poll until the work is completed or the server needs to make a call to a callback url. At the very least you need to do the work in another thread if not using hangfire or running it on a different server or something.

rarbatrol
Apr 17, 2011

Hurt//maim//kill.
True. Microsoft put together some standards for long running stuff: https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#131-resource-based-long-running-operations-relo

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Is Entity Framework a good solution for connecting to an existing SQL database that gets used by other stuff? The tutorials I read are all so hopped up about how it can auto-create tables for itself and I do not want it to do that. It also seems like my options are either that or going back to manually writing everything out using SqlCommand. What was so frigging wrong with linq to sql, anyway? I liked not having to manually write out the classes and do the mapping.

Eldred
Feb 19, 2004
Weight gain is impossible.

CapnAndy posted:

Is Entity Framework a good solution for connecting to an existing SQL database that gets used by other stuff? The tutorials I read are all so hopped up about how it can auto-create tables for itself and I do not want it to do that. It also seems like my options are either that or going back to manually writing everything out using SqlCommand. What was so frigging wrong with linq to sql, anyway? I liked not having to manually write out the classes and do the mapping.

This thread seems to like Dapper better but yes, Entity Framework can do that.

spaced ninja
Apr 10, 2009


Toilet Rascal

CapnAndy posted:

Is Entity Framework a good solution for connecting to an existing SQL database that gets used by other stuff? The tutorials I read are all so hopped up about how it can auto-create tables for itself and I do not want it to do that. It also seems like my options are either that or going back to manually writing everything out using SqlCommand. What was so frigging wrong with linq to sql, anyway? I liked not having to manually write out the classes and do the mapping.

Haven’t used EF in a while but pretty sure this is what you want. You can auto generate the entities from the db.

https://docs.microsoft.com/en-us/ef/ef6/modeling/designer/workflows/database-first

Sir DonkeyPunch
Mar 23, 2007

I didn't hear no bell
Yeah, Code First is the golden child, but Database First is an option (often one more suited to real world)

The “problem” you’ll face is that depending on what kind/frequency of changes the actual owners make to these tables, full fat* ORMs will make you more likely to have to do a code change to accommodate it. Things like names or types on columns you don’t even use, for instance.

*I’m sure there is a more common name to distinguish between EF and Dapper/PetaPOCO but I don’t know it

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Sir DonkeyPunch posted:

*I’m sure there is a more common name to distinguish between EF and Dapper/PetaPOCO but I don’t know it

Dapper/PetaPoco are known as micro-ORM, whereas EntityFramework/NHibernate are full featured ORM. Micro-ORM tools generally just give you a type-safe approach for writing SQL without providing much more than that - full featured ORM tools automate generating SQL from code and have built in features for migrations, change tracking, lazy-loading and various other features.

distortion park
Apr 25, 2011


CapnAndy posted:

Is Entity Framework a good solution for connecting to an existing SQL database that gets used by other stuff? The tutorials I read are all so hopped up about how it can auto-create tables for itself and I do not want it to do that. It also seems like my options are either that or going back to manually writing everything out using SqlCommand. What was so frigging wrong with linq to sql, anyway? I liked not having to manually write out the classes and do the mapping.

You can use thread favourite library Dapper for this. It's really just really nice syntactic sugar over SqlCommand - you'll still have to declare your result classes but it will do the mapping for you.

NihilCredo posted:

God I love this language :fap:



And yeah, there's probably a bunch more formats I didn't know about. And I could have just googled a few well-tested regexes. But it's what hobby projects are for.

Are you using a tool or something to auto format this? Formatting is the thing I struggle with the most with f#

Ola
Jul 19, 2004

pointsofdata posted:


Are you using a tool or something to auto format this? Formatting is the thing I struggle with the most with f#

I'm guessing Fantomas.

Which editor do you use? I use regular Visual Studio for C#/F#. There is an extension called F# Formatting available there which wraps Fantomas, but it's broken for me. It removes lines etc. Others on my team use VS code like NihilCredo or Rider, they seem to get on well. I'm going to try VS code for C#/F# instead from the next project.

redleader
Aug 18, 2005

Engage according to operational parameters

pointsofdata posted:

You can use thread favourite library Dapper for this. It's really just really nice syntactic sugar over SqlCommand - you'll still have to declare your result classes but it will do the mapping for you.


or just return dynamic!


... :eng99:

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

pointsofdata posted:

Are you using a tool or something to auto format this? Formatting is the thing I struggle with the most with f#

The VSCode plugin does include the Fantomas formatter now, but I personally never use it, I find that I often want to deviate from the 'default' style to make a particular function read better.

Eg. the fromString function is a trivial wrapper so it works better as a one-liner IMO, but normally I'd always line break a try/with block.

Nostalgamus
Sep 28, 2010

mystes posted:

Uh, you're using await, right? If so, be aware that the whole point of awaiting an asynchronous function is that you want to resume the calling function when the result is obtained, so consider if that's what you really want to do here.

The Web Service appears to using the Event-based Asynchronous Pattern, so there's no Task object. As far as I understand, await needs one of those to work.

New Yorp New Yorp posted:

Your web service shouldn't take 30 minutes to run without returning a result. You shouldn't start a process in a web application that takes 30 minutes to run, ever, synchronously or asynchronously.

I was starting to suspect "the design is fundamentally wrong" was the right answer, so thanks for confirming that. I was starting so pretty early on due to the fact that the input parameter is a file path, i.e. the file in question need to already be on the server. In my defense, I did not create the Web Service, just got asked to make a web page that interfaces with it.

In either case, it seems to me like the best way to do this without major restructuring is to add a regular, synchronous function to the Web Service that starts a new thread for the big process, and then the web site can use the functions for checking progress (which were the main point of the web page).

Ola
Jul 19, 2004

NihilCredo posted:

The VSCode plugin does include the Fantomas formatter now, but I personally never use it, I find that I often want to deviate from the 'default' style to make a particular function read better.

Eg. the fromString function is a trivial wrapper so it works better as a one-liner IMO, but normally I'd always line break a try/with block.

Do you format that by hand then? I also see you use the font that makes -> and |> look super nice. I think I'm in some sort of makeup dilemma, I want the natural beauty of your F# but I'm not sure I'm willing to do the job that natural beauty takes.

Eldred
Feb 19, 2004
Weight gain is impossible.

Nostalgamus posted:

The Web Service appears to using the Event-based Asynchronous Pattern, so there's no Task object. As far as I understand, await needs one of those to work.


I was starting to suspect "the design is fundamentally wrong" was the right answer, so thanks for confirming that. I was starting so pretty early on due to the fact that the input parameter is a file path, i.e. the file in question need to already be on the server. In my defense, I did not create the Web Service, just got asked to make a web page that interfaces with it.

In either case, it seems to me like the best way to do this without major restructuring is to add a regular, synchronous function to the Web Service that starts a new thread for the big process, and then the web site can use the functions for checking progress (which were the main point of the web page).

That can work, or you can use a pattern like this: https://docs.microsoft.com/en-us/azure/architecture/patterns/async-request-reply

Is there state for the 30 minute call you can check or is it just in memory? Could just drop the request, have it return an ID of some sort, then redirect to a status page that checks on it if you have some form of state. Saves you from having to use an extended timeout period (which might cause other problems) too.

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters
async/await in old-timey asp.net (.aspx, .ashx, .asmx) is a minefield, but i agree that in this case async is the wrong approach. personally, i'd use hangfire because i hate myself and enjoy the ease of getting started combined with the unintuitive behavior in edge cases

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