epalm posted:There's definitely a lot of mediocre (or just outdated) material out there. 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.
|
|
# ? Jan 4, 2021 03:15 |
|
|
# ? Jun 8, 2024 10:19 |
|
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)
|
# ? Jan 4, 2021 03:35 |
|
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.
|
# ? Jan 4, 2021 05:16 |
|
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.
|
# ? Jan 4, 2021 05:20 |
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.
|
|
# ? Jan 4, 2021 19:49 |
|
God I love this language 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.
|
# ? Jan 4, 2021 21:28 |
|
NihilCredo posted:God I love this language 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.
|
# ? Jan 4, 2021 21:36 |
|
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.
|
# ? Jan 4, 2021 21:42 |
|
Is pre-declaring the error like that just a style preference?
|
# ? Jan 4, 2021 23:22 |
|
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.
|
# ? Jan 5, 2021 00:25 |
|
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.
|
# ? Jan 5, 2021 07:42 |
|
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.
|
# ? Jan 5, 2021 16:45 |
|
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.
|
# ? Jan 5, 2021 16:51 |
|
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.
|
# ? Jan 5, 2021 21:03 |
|
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.
|
# ? Jan 6, 2021 04:50 |
|
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.
|
# ? Jan 6, 2021 05:24 |
|
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"
|
# ? Jan 6, 2021 17:20 |
|
that's a 404
|
# ? Jan 6, 2021 19:23 |
|
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 . 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:
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.
|
# ? Jan 7, 2021 02:16 |
|
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.
|
# ? Jan 7, 2021 03:17 |
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
|
|
# ? Jan 7, 2021 05:15 |
|
Riot Bimbo posted:Aaaaaahhhh!!!! it's sorta working!!!! Nice, love that feeling.
|
# ? Jan 7, 2021 18:43 |
|
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?
|
# ? Jan 7, 2021 21:24 |
|
Nostalgamus posted:I've been fiddling with async functions, and getting really confused.
|
# ? Jan 7, 2021 21:31 |
|
Nostalgamus posted:I've been fiddling with async functions, and getting really confused. 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.
|
# ? Jan 7, 2021 21:43 |
|
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.
|
# ? Jan 7, 2021 21:51 |
|
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
|
# ? Jan 7, 2021 23:02 |
|
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.
|
# ? Jan 7, 2021 23:33 |
|
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.
|
# ? Jan 7, 2021 23:59 |
|
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
|
# ? Jan 8, 2021 00:16 |
|
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
|
# ? Jan 8, 2021 04:13 |
|
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.
|
# ? Jan 8, 2021 05:58 |
|
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 Are you using a tool or something to auto format this? Formatting is the thing I struggle with the most with f#
|
# ? Jan 8, 2021 09:36 |
|
pointsofdata posted:
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.
|
# ? Jan 8, 2021 09:45 |
|
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! ...
|
# ? Jan 8, 2021 10:25 |
|
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.
|
# ? Jan 8, 2021 12:21 |
|
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).
|
# ? Jan 8, 2021 17:53 |
|
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. 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.
|
# ? Jan 8, 2021 23:49 |
|
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. 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.
|
# ? Jan 9, 2021 07:13 |
|
|
# ? Jun 8, 2024 10:19 |
|
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
|
# ? Jan 9, 2021 08:54 |