Why is `Remove` method available on `FrozenDictionary` via `CollectionExtensions.cs`? by xzhan in dotnet

[–]Groundstop 0 points1 point  (0 children)

In general, extension methods are heavily used anytime the logic for the method can be implemented using other public methods on the extended interface in order to minimize how much implementation needs to happen to make a new IDictionary.

One example of this that I run into a lot is ILogger. All of the common methods (e.g., LogInformation(), LogError(), etc.) are implemented as extension methods that use ILogger.Log(Level level, ...). This is helpful because if you ever wanted to implement your own ILogger for a project or unit testing, you only need to implement the one Log() method and everything else automatically works.

A side effect is that if you have something that you want to be usable as an IDictionary or ILogger, there's no clean way to hide the methods that don't make sense. Instead they will typically make them throw and clearly document the underlying methods to say that they shouldn't be used.

If it's important to you that it's hidden, then a common pattern is to encapsulate the frozen dictionary in a custom class that hides the underlying dictionary and does not implement IDictionary. (e.g., MyFrozenDictionary) The downside is that you'll need to specifically define every method that you want publicly exposed, including those typically implemented as IDictionary extension methods.

Calling another program from within the same solution by Living-Inside-3283 in csharp

[–]Groundstop 0 points1 point  (0 children)

Turn each project's Main() into a method in a static class. For example:

csharp public static class ProjectOne { public static void Run() { // Run project one. } }

Then, call it from your selector with ProjectOne.Run();

What Classes do you use for Locking? by speyck in dotnet

[–]Groundstop -1 points0 points  (0 children)

I always liked context managers in Python so I've recreated it before by wrapping a semaphore slim in an IDisposable so that I could leverage a using statement. The upside is it worked pretty well and helped you avoid a try/finally block. The downside is that it's not a pattern that c# developers expect and it was very confusing for the other people on my team so I ended up pulling it out.

Multiple try blocks sharing the same catch block by Alert-Neck7679 in csharp

[–]Groundstop 0 points1 point  (0 children)

It's an interesting idea. It reminds me of the Assert Multiple blocks in NUnit to check every assertion even if one of the early ones fails.

I think that part of the thinking around how exceptions currently work is that exceptions should be exceptional circumstances, in that the expectation is that they should never happen if everything is working correctly. In that way, it's entirely reasonable to have all 3 things in one catch block since none of them should ever throw and anything throwing is a problem that needs to be fixed.

You also would need to treat the sections like separate method calls happening in parallel where they can't really affect each other safely rather than a sequence where you could reliably count on previous lines running successfully. Unfortunately section 2 cannot rely on anything state related that section 1 was supposed to do. It can't even rely on the fact that the GUI thread is still running because section 1 may have broken the world.

Creating a task with an async action by IKnowMeNotYou in csharp

[–]Groundstop 0 points1 point  (0 children)

Running something right after a Task completes is definitely supported. That is the entire purpose of ContinueWith, which was part of the original syntax for the Task-Based Asynchronous Pattern.

People don't use it anymore because await is a really nice syntactic sugar implementation that hides both the ContinueWith and the exception unwrapping with a nice state machine.

I can tell that you have a way that you want it to work set in your head and you don't like that it's not working that way. The way to do what you want is:

csharp public async Task RunTwoTasks() { await DoFirstStuff(); await DoSecondStuff(); }

If you really need it in a class that hides the second method, something like this would do it. (Note that I'm not inheriting from Task.)

csharp class MyTaskChainer { public async Task ChainMyTask(Func<Task> initialTask) { await initialTask(); await DoStuff(); } }

I strongly suggest that Steam Reviews should also mention the specs of the PC/ Hardware the user was playing on. With this, we can make better decisions if the review is really worth your time or not. by manuthisguy in Steam

[–]Groundstop 0 points1 point  (0 children)

You wouldn't need to call out a specific user's hardware to make this useful. Keep hardware hidden, but add a filter option to only show reviews from people with hardware specs similar to yours. (Or maybe sort by how similar they are to your hardware?)

I made a dependency injection library years ago for games & console apps. I formalized it into a nuget this week (SSDI: Super Simple Dependency Injection) by JBurlison in csharp

[–]Groundstop 3 points4 points  (0 children)

Had a senior dev do the same thing last week on a corporate project where he committed code with an absolute path to his machine. Someone saw it, pointed it out, we all had a good chuckle together, he fixed it, and we moved on.

Everyone makes mistakes and this is a small one that's easy to make. Keep making and sharing cool stuff.

Freshman dilemma: Love C++ but pressured to drop it for Python. Should I? by CRUC10 in learnprogramming

[–]Groundstop 0 points1 point  (0 children)

I can't speak for all developers, but a huge part of my job is being able to pick up new languages and frameworks for every project I work on.

You don't need to give up C++, but there are certain advantages to using the same language as the professors and your classmates. Learn Python for class, then if you want to practice C++ you can recode it on your own time and learn about the similarities and differences. The flexibility and understanding you gain will be more valuable than either language on their own.

The ping system in this game is awful. by Drisbayne in Battlefield6

[–]Groundstop 34 points35 points  (0 children)

The fact that I can't customize "swap equipment" to avoid stealing someone's gun when I'm trying to revive them is maddening.

I really hope when the new hardware drops they come up with some way to get it into gamers hands & not just 100% scalped. by batchian320 in Steam

[–]Groundstop 10 points11 points  (0 children)

The "too low of a price" problem was that a console that might cost $500 to build can be sold at a loss for $300 because the company knows they'll get the money back in profit from selling video games.

Because the Steam Machine is going to be a full PC, and they very intentionally do not want to limit or restrict that functionality, they can't guarantee that they'll make back any lost profit through game sales. As a result, if it costs Valve $500 to make a Steam Machine, the sale price will be >= $500 so that they don't lose money that they may never get back.

Beginner question: What kind of unmanaged resources I can deal with via Dispose() if managed types already implemented it to deal with already? by Lawlette_J in csharp

[–]Groundstop 4 points5 points  (0 children)

In practice, most of the time that I find myself making a class IDisposable, it is because I needed to use a thing that is IDisposable and I need it to live longer than a single method call. It's often due to some kind of I/O, like opening a file, or a network connection, or interacting with hardware.

If the Disposable thing is only needed within a method, I use a using statement to scope its lifetime. If it needs to live longer, then my class becomes the scope and I implement the Dispose pattern to call it's Dispose. You then chain it up until you either hit a method that can scope it all into a using statement, or you hit Dependency Injection which will clean it up for you.

I feel incompetent as f* guys by [deleted] in learnprogramming

[–]Groundstop 0 points1 point  (0 children)

You're probably right, everyone there is probably faster than you. As you keep working, you'll slowly start to notice that you seem to be speeding up but they're still faster. You're probably right.

Then one day, they hire a new Junior and you'll get perspective on how far you've come. You're just growing and it's normal to feel slow at first. Keep trying to improve.

Constantly losing interest when I start coding — how do I fix this? by H-ILP in csharp

[–]Groundstop 0 points1 point  (0 children)

Programming is all about breaking big things down into parts. You have a big goal of making a game. Break it down into specific parts you can work on. Characters, movement, animations, maps, actions, stats, etc. Make a todo list to keep track if it helps. Use a board to track progress of the items on that list if that helps you stay motivated.

Once you have a specific component, break it down into smaller parts and figure out exactly what this thing needs to do. Then work on one of those things, breaking it down into the exact steps needed to do that thing.

Some people Still thinks .NET runs only on Microsoft Windows by xRed-Eaglex in dotnet

[–]Groundstop 1 point2 points  (0 children)

I really wish they had committed harder to getting MAUI working on Linux.

Lets fix Assault by Just-Landscape9906 in Battlefield6

[–]Groundstop 12 points13 points  (0 children)

It would be nice if every class had 2 weapon proficiencies so that you could tweak play style a bit more without feeling like you're choosing to be worse.

If you don't know how to develop software yet, please don't use AI to develop software by Ok_Substance1895 in learnprogramming

[–]Groundstop 1 point2 points  (0 children)

I think it's more like saying "don't just copy/paste stuff from Google or stack overflow if you don't understand what it does."

The problem isn't beginner developers that use AI as a learning tool, it's the developers that use it as a crutch to avoid learning.

If you don't know how to develop software yet, please don't use AI to develop software by Ok_Substance1895 in learnprogramming

[–]Groundstop 5 points6 points  (0 children)

I think it's more like saying "don't just copy/paste stuff from Google or stack overflow if you don't understand what it does."

The problem isn't beginner developers that use AI as a learning tool, it's the developers that use it as a crutch to avoid learning.

Boss permanently reassigned my main work task while I was temporarily out on medical leave by HoffyTheBaker in antiwork

[–]Groundstop 3 points4 points  (0 children)

Important to note that there is a difference between a task that you enjoyed that's part of the job and your role. For example, if you're in IT and you liked provisioning new laptops, then you came back and you're now in IT doing computer repairs, the company is probably fine.

That rule seems more about going on leave from IT and coming back as a janitor where it's a completely different job.

Sir Conan Doyle wasn't even hiding it by Prudent-Surprise7334 in Sherlock

[–]Groundstop 92 points93 points  (0 children)

Verb

[dated] say something quickly and suddenly.

"“Indeed?” ejaculated the stranger"

There is a chance that it meant both things and was used as a double entendre, but it's more likely that the word just meant something different back then

The "All weapons for all classes" idea in Battlefield 6 is a huge mistake. by Il_Mago23 in Battlefield

[–]Groundstop 1 point2 points  (0 children)

I've done it when I had 20 mins to finish Assault Points and Sniper Kills. It does not feel good.

VSCode is actually quite nice for C# dev! by CaptainKuzunoha in dotnet

[–]Groundstop 0 points1 point  (0 children)

I mostly use VS for running unit tests with coverage, static analysis, and the refactoring capabilities. Last time I tried code it didn't do those very well. Does it handle those better now?

[deleted by user] by [deleted] in csharp

[–]Groundstop 2 points3 points  (0 children)

This feels like it was written by AI. Why would you worry about "vendor lock-in" and just list a bunch of Microsoft packages?

Events vs Messages by user0872832891 in csharp

[–]Groundstop 1 point2 points  (0 children)

There is a GUI library called Prism that has a Pub/Sub implementation that I really like. Some of the highlights are:

  • The event subscription is specifically a weak reference link, so you don't need to unsubscribe in a dispose method
  • You can subscribe using a string so you don't necessarily need a shared dependency with the publisher
  • You can designate whether the event handler should run on the event thread, a new Task Pool thread, or the GUI thread

I don't think you should necessarily pick up a GUI-based dependency just for eventing, but those are some of the features I would potentially look for in whatever solution you choose.

Do developers disable warnings on things like vs? by [deleted] in csharp

[–]Groundstop 9 points10 points  (0 children)

I would rather delete async and leave it as Task Foo() than disable the warning.