|
After 7 and a half years and over 400 pages, it's time for a new .NET megathread! The old thread is here. What is .NET? Wikipedia posted:[The] .NET Framework ... is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library known as Framework Class Library (FCL) and provides language interoperability (each language can use code written in other languages) across several programming languages. Programs written for .NET Framework execute in a software environment (as contrasted to hardware environment), known as Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework. What languages can I use write to fancy-pants .NET applications?
What's awesome about .NET languages? First off, Microsoft is constantly improving the framework and languages -- there's usually a new .NET release every 1-2 years, which brings new versions of C#, VB, F#, etc. Since our last megathread in January 2007, dozens of new features have come along, several of which changed the way we write code on a day-to-day basis. The big ones are:
Plus, Microsoft has created some of the best tooling around. Visual Studio is the IDE that every other IDE wishes it could be, and the .NET framework is huge and has built-in classes and methods to do just about everything. I want to develop using Visual Studio, but I'm not paying for it! That's fine, Microsoft has Visual Studio Community for you. Microsoft retired the rather limited "Express" edition of Visual Studio in 2014 in favor of a "Community" edition, which is free to use and full-featured. Should I be using source control? Yes! If you want to stay within the Microsoft stack:
TFS is the all in one ALM solution for the Microsoft world -- it has project planning, source control, automated build, and automated release. It's a solid product, but it requires some forethought when setting it up. The standard source control model is centralized, but it also supports distributed version control by way of native Git support as of TFS2013. If you don't care about the Microsoft stack:
Really, the important thing is to use some kind of source control, even for hobbyist projects. It'll save you a lot of pain in the long-run, and possibly even in the short-run. It's entirely possible to switch source control systems if you don't like the one you're using, although the amount of pain in migrating your change history may be prohibitive, depending on where you're going from/to. I want to make a website. What should I do? ASP .NET MVC. Don't use ASP .NET WebForms. WebForms was an interesting attempt by Microsoft to make developing web applications closer to developing desktop applications. It didn't really accomplish that, and at this point it really just gets in the way of writing modern, dynamic sites. I want to make a desktop application. What should I do? WPF. Make sure you follow the Model-View-ViewModel (MVVM) pattern. Don't use WinForms. The WinForms architecture practically forces you to mix your presentation logic with your business logic, which is never a good thing. I want to make a "Modern UI"/Metro/Windows Store application! See above, but also look at Microsoft's Windows Store site. I want to write a mobile app for iOS or Android! Xamarin I want to do some sort of stuff involving a database! Manually writing queries is for suckers! Use an ORM, but not LINQ to SQL. LINQ to SQL is dying/dead. Microsoft's replacement is Entity Framework. Personally, I prefer NHibernate, but both are better than LINQ to SQL. Also, ShaunO posted:If you absolutely have to write ad-hoc queries, your queries don't map well to a full-blown ORM, your application is so small can't justify using a full-blown ORM, or you want to query some other IDbConnection provider. Friends don't let friends use DataTables or reinvent the wheel, use dapper. I want to run my .NET stuff on a non-Windows OS! Mono is an open-source implementation of the CLR for non-Windows OSes. Should I be writing unit tests? Yes! There are some links to a few different unit testing frameworks in this post, but don't worry too much about which one you choose. Writing testable code is harder than writing test code, and the frameworks are all pretty similar to one another. Books/References General Unit Testing
Frameworks/Tools
Visual Studio Plugins
Thanks to Drastic Actions, mortarr, Dust!!!, ShaunO, Dr. Poz, Knyteguy, GrumpyDoctor, and Destroyenator, wwb, and other people I probably forgot to include here for suggestions and links! New Yorp New Yorp fucked around with this message at 00:08 on Apr 17, 2015 |
# ? Jun 20, 2014 19:46 |
|
|
# ? May 3, 2024 01:55 |
|
Update: 11/12/2014: VS2015, C#6/VB14, .NET 2015ljw1004 posted:Plug: New Yorp New Yorp fucked around with this message at 17:50 on Nov 12, 2014 |
# ? Jun 20, 2014 19:47 |
|
How do GhostDoc and Sandcastle/SHFB compare?
|
# ? Jun 20, 2014 20:07 |
|
(from old thread)zerofunk posted:Has anyone ever had issues with different results from using the VS 2012 Test Runner and running mstest.exe from the command line? We have some Automapper Exceptions thrown due to some type mismatches (silly things like float -> double, and int? -> int). These are causing test failures if I run our tests from mstest.exe. When I run directly from VS2012, everything passes. I'm not even sure where to start in figuring out why that is happening. Could be that VS is using one set of Test Settings and running via command line you're using a different (default/none) set of Test Settings. Yet another reason to not use MSTest for unit testing. edit: You can check if VS is using one in the Test -> Test Settings menu.
|
# ? Jun 20, 2014 20:15 |
|
Thanks, I'll look into that on Monday. I didn't set all of this up initially, so I'm not really sure what's in the test settings. I've inherited a lot of decisions on this in terms of libraries/frameworks. Thankfully the project is still very new so it's not too difficult to shift directions on some things.
|
# ? Jun 20, 2014 20:22 |
|
Has anyone tried out ASP.NET vNext on a Linux/Mac box yet? Unfortunately I don't have any box to work on right now (can't spin up a VM on the work PC and don't have the RAM to do it at home) but depending on how well it works I'd consider switching up the hosting for my personal site, as well as offering non-windows hosted web applications for people.
|
# ? Jun 20, 2014 20:33 |
|
Nice op. I just had tfs needlessly complicate things for me yet again, so allow me to re-endorse using Git flavored repos. Makes everything much better.
|
# ? Jun 20, 2014 20:35 |
|
Dietrich posted:Nice op. I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects. If so, I'd try setting up a Git repo just to play with. It's just as easy to set up Git in VS online as it is to use their TFS. I just thought I would be forced to use a command line or third party tools to use it?
|
# ? Jun 20, 2014 20:41 |
|
crashdome posted:I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects. If you want to anything fancy (e.g. any history rewrites), you'll have to go third-party, but basic commit/push/fetch/branch stuff is done easily within VS.
|
# ? Jun 20, 2014 20:43 |
|
crashdome posted:I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects. I'm not a fan of Git, but every time I talk about why I don't like Git I get dogpiled by people telling me I'm stupid, so I won't get into it. The Git tools in VS2013 are solid. They're not great, but they're usable and getting better with every update. Doesn't hurt to try it... just open up the Team Explorer and add a new repo, and you should be off and running. If you have any TFS questions, you can PM me or ask here... I know TFS like the back of my hand.
|
# ? Jun 20, 2014 20:48 |
|
crashdome posted:I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? quote:Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects. the vs git integration was not great until recently, but in 2013 i like it a lot
|
# ? Jun 20, 2014 21:08 |
|
OK, thanks everyone. I don't want to cause a rift but, I just never heard or saw anyone talk about how easy Git was. Only that it was "better" and then spout about command line this and command line that. I will try it out. Right now, environmentally TFS might suit me better. Although, I do want to not appear stupid when confronted with a Git repo in the future either. Personally, TFS seems ok to me. I like having a connection to my VS online account and can see and manipulate projects and workspaces without leaving VS. Although, I do not connect to any other TFS server and do not have to split projects or work across multiple repos. The only thing that confused me about TFS was I got a new device, loaded up VS2013, and promptly got lost setting up ONE workspace in a custom located local folder for a few related projects. I managed to work it out but, the UI is confusing for server connections (and don't get me started on logging out and logging in as another user). However, UI design overall seems great - once you are setup.
|
# ? Jun 20, 2014 21:35 |
|
Get the Git Extensions and download the sourcecode provider for VS. Works pretty much as it should.
|
# ? Jun 20, 2014 21:40 |
|
Pretty sure the thread title should be await GetGoodPostsAsync()
|
# ? Jun 20, 2014 22:27 |
|
WHERE MY HAT IS AT posted:Pretty sure the thread title should be await GetGoodPostsAsync() async/await introduces just as many issues as it solves imo
|
# ? Jun 20, 2014 22:50 |
|
GrumpyDoctor posted:How do GhostDoc and Sandcastle/SHFB compare? Theyre different things entirely Sandcastle compiles the inline documentation to a set of web pages or whatever. As far as I can tell, GhostDoc is good for automatically writing a comment stating that GetButts() gets the butts. Did they add compilation or something?
|
# ? Jun 20, 2014 23:19 |
|
Malcolm XML posted:async/await introduces just as many issues as it solves imo What issues does it introduce?
|
# ? Jun 20, 2014 23:33 |
|
chmods please posted:Theyre different things entirely Sandcastle compiles the inline documentation to a set of web pages or whatever. As far as I can tell, GhostDoc is good for automatically writing a comment stating that GetButts() gets the butts. Did they add compilation or something? According to the website the Pro version will do it. After reading a little bit more I think I just don't understand what's useful about being able to automatically infer that GetButts() gets butts, but to each their own I guess And while we're on the subject, maybe SHFB should be in the OP?
|
# ? Jun 21, 2014 00:31 |
|
Ithaqua posted:What issues does it introduce? Stupid things like configure await and having to manually spill variables (!!!!) to reduce allocations is just tedious Also it conflates a CPS rewriting sugar (await) with parallelism which honestly is more confusing. Something along the lines of haskell async or parallel might have been cleaner I just don't think it's at all clear how async await works behind the scenes and how much control you have over it: the actual generated code is not even CPS it's a funky state machine with a bunch of gotchas. It needs some nicer combinators and good spec of its semantics
|
# ? Jun 21, 2014 00:59 |
|
I really like what async/await gives you, but I do agree that there are some nasty hidden gotchas. My main complaint is that you're not able to easily call an async method synchronously. Doing that is basically a recipe for deadlocks, but what option do I have if I'm not running in an async ready context (e.g. console app)? This forces most libraries to expose both synchronous and asynchronous method calls which just pollutes their APIs. If calling asynchronous methods synchronously was easy then we could get rid of this silly *Async duplicate method convention and just expose async methods.
|
# ? Jun 21, 2014 01:12 |
|
Visual Studio question: I'm curious as to whether there is a productivity extension that replicates Sublimes' features like line duplication, control+d selection searching, or multiple editing locations. What I'm asking for is a Sublime flavoured Visual Studio. After working with Sublime for so long I really miss being about to ctrl+d a variable or string or whatever, then tap an arrow key to start typing after all of them at once. I was a big fan of being able to highlight something then type in a brace of some sort, and it'd put one either side of the selection.
|
# ? Jun 21, 2014 07:03 |
|
ATM Machine posted:Visual Studio question: I'm curious as to whether there is a productivity extension that replicates Sublimes' features like line duplication, control+d selection searching, or multiple editing locations. ReSharper does that kind of stuff.
|
# ? Jun 21, 2014 07:06 |
|
Bognar posted:I really like what async/await gives you, but I do agree that there are some nasty hidden gotchas. My main complaint is that you're not able to easily call an async method synchronously. Doing that is basically a recipe for deadlocks, but what option do I have if I'm not running in an async ready context (e.g. console app)? This forces most libraries to expose both synchronous and asynchronous method calls which just pollutes their APIs. If calling asynchronous methods synchronously was easy then we could get rid of this silly *Async duplicate method convention and just expose async methods. What's wrong with Task.RunSynchronously or even just Result? Well, I mean, what's wrong that some other syntax would fix?
|
# ? Jun 21, 2014 07:28 |
|
RICHUNCLEPENNYBAGS posted:What's wrong with Task.RunSynchronously or even just Result? Well, I mean, what's wrong that some other syntax would fix? If you have async code and try to use it synchronously, Bad Things can happen in the form of deadlocks; the async code just waits for something that's never going to happen because everything else is held up waiting for the task to complete. Of course it all depends on the synchronization context... a console app will be fine because it has no synchronization context, it just passes it off to the task scheduler. [edit] Even though Stephen Cleary irks me on a personal level, he knows this poo poo inside and out and explains it really well: http://msdn.microsoft.com/en-us/magazine/jj991977.aspx New Yorp New Yorp fucked around with this message at 07:48 on Jun 21, 2014 |
# ? Jun 21, 2014 07:37 |
|
Ithaqua posted:If you have async code and try to use it synchronously, Bad Things can happen in the form of deadlocks; the async code just waits for something that's never going to happen because everything else is held up waiting for the task to complete. Of course it all depends on the synchronization context... a console app will be fine because it has no synchronization context, it just passes it off to the task scheduler. Yeah, but I don't see an easy fix for that.
|
# ? Jun 21, 2014 08:05 |
|
The 'easy fix' is typically to ConfigureAwait(false) so that you don't get marshalled onto a blocked context. however it's irritating and gives up many of the actual benefits of async. The 'right fix' is that async code should be top-down, not bottom-up. The requirement to use async apis is an asynchronous event loop. Such as: WPF event-handing "async void"s, or ASP.NET actions. if you don't have one of those available, you have to return Task yourself; it can't be safely encapsulated. People get in trouble when they try to use async methods *internally* to implement a non-async thing. Even given that constraint, await is pretty fantastic.
|
# ? Jun 21, 2014 11:46 |
|
Gul Banana posted:The 'easy fix' is typically to ConfigureAwait(false) so that you don't get marshalled onto a blocked context. however it's irritating and gives up many of the actual benefits of async. They tried to get monads in the language with linq and it was ok but I have rarely seen generators (and the difference between Ienumerator and ienumerable is subtle and almost always you actually want the former) Now they've gotten a monad that isn't really a container and in order to sneak it in without the ability to have do-notation they put in await which manually performs CPS and then optimizes it out by using a state machine analogous to yield return But manually implemented generators are extremely rare--everyone usually uses the combinators from linq instead and uses icollection as the base In this case everyone has to deal with the gotchas of implemented async generators via await since the libraries aren't rich enough and there isn't enough power to have monad manipulation defined generically And then there's synch context which is really goddamned subtle and even Jon loving skeet says he doesn't really understand it so how do you expect workaday devs to diagnose why deadlocks are happening in something they were sold as the best asynchronous pattern? I wanna say if they dropped the async void compat layer and made it so that async behaved more like Haskell async by using speculative parallelism it might be better
|
# ? Jun 21, 2014 13:09 |
|
that would require investing any money in WPF ever again, though. so it ain't gonna happen
|
# ? Jun 21, 2014 18:43 |
|
for the other stuff it's like.. you're totally right that this stuff is not correctly generalised as it could be if they'd just put a little more mathematics into it. linq overall reads as a *rediscovery* of monads, to the point that using SelectMany as bind/>>= is needlessly obtuse. however: there's an alternative case to be made that it's a useful extraction of the common-case benefits into comprehensible patterns. *IF* you accept the premise that M[a] is too hard for many developers, then the list monad in the form of IEnumerable<a> is a great compromise. collections cover a lot of stuff! collections with generators cover more - it's rare for people to use interesting generators, but being able to do this sort of thing code:
there's evidence out there. note that Scala, which already had Future and generalised do-notation, added async & is chatting happily about it. heck in .net we already had Linq 2 Tasks, weird as it was. i've seen people write this: code:
|
# ? Jun 21, 2014 18:53 |
|
so with List and Future you have maybe 90%, 99% of the monadic power that Joe Applicationdeveloper can really use. each gets its own special case syntax. for that matter so does IO, which has "the assignment operator". Microsoft's implicit argument here is that by addressing each of these use cases as its EROI becomes high enough, they're frogmarching the world forward as fast as it will grumbly-shuffle. until someone comes up with a piece of software that doesn't need to be maintained, idk that we have proof otherwise.
|
# ? Jun 21, 2014 18:58 |
|
Gul Banana posted:so with List and Future you have maybe 90%, 99% of the monadic power that Joe Applicationdeveloper can really use. each gets its own special case syntax. for that matter so does IO, which has "the assignment operator". Microsoft's implicit argument here is that by addressing each of these use cases as its EROI becomes high enough, they're frogmarching the world forward as fast as it will grumbly-shuffle. until someone comes up with a piece of software that doesn't need to be maintained, idk that we have proof otherwise. well clearly not, since they're adding the chained null thing which is the Maybe/Option monad is there anything against dumping classes and only using nullable structs? Gul Banana posted:so with List and Future you have maybe 90%, 99% of the monadic power that Joe Applicationdeveloper can really use. each gets its own special case syntax. for that matter so does IO, which has "the assignment operator". Microsoft's implicit argument here is that by addressing each of these use cases as its EROI becomes high enough, they're frogmarching the world forward as fast as it will grumbly-shuffle. until someone comes up with a piece of software that doesn't need to be maintained, idk that we have proof otherwise. Try using both at once. It's a clusterfuck and you actually need monad transformers to deal with it properly. They basically tried to hide the theoretical complexity but in doing so opened a giant can of worms. Explict > implicit and unless there is a very clear way of translating from implicit to explicit ( do-notation is basically just (>>=) and lambda-binding) there's gonna be problems F# had async workflows, which are really nice and much better for a lot of async stuff than the TAP :http://tomasp.net/blog/csharp-async-gotchas.aspx/ lcw014 or w/e get in here and explain yourself
|
# ? Jun 21, 2014 21:05 |
|
Malcolm XML posted:the difference between Ienumerator and ienumerable is subtle and almost always you actually want the former Any chance you could elaborate on this?
|
# ? Jun 21, 2014 23:18 |
|
aBagorn posted:Has anyone tried out ASP.NET vNext on a Linux/Mac box yet? I'd be interested if you do get this working. I have the latest master of mono running fine but I'm having issues with the K runtime and running kpm restore against the web-based samples. Just weird mono exceptions and x509 certificate errors when trying to retrieve the AspNet hosting related libraries - even though I've trusted all of the right SSL certs, as far as I know. https://github.com/aspnet/home - with these samples, I was able to get the console app working fine with kpm restore, but the web samples just throw a poo poo fit. I've given up for now, I tried the mono IRC channel for help but it's dead and am not sure where to go from there, maybe I'll log an issue on that github project. I tried using this prebuilt docker image https://registry.hub.docker.com/u/akoeplinger/mono-aspnetvnext/ as well but have exactly the same issues, though my own environment is pretty much the same anyway, so not surprising but it looks like it's only been broken for the past couple of weeks. ShaunO fucked around with this message at 01:19 on Jun 22, 2014 |
# ? Jun 22, 2014 01:17 |
|
list+future IS a real problem. at that point you need IObservable, which is sort of half built-in to the language and doesn't follow the same api conventions... my only defense of .NET there is "many programs don't need it". but one of my current projects does, and suffers from the lack ;_; it's an ORM which hasn't been able to move to a fully asynchronous read-side API, because that doesn't compose with IQueryable. even internally it has problems needing to do things like reify sequences into lists so that disposal of db handles can take place - unnecessary data copies b/c the streaming and iterating abstractions don't compose with the deferral and concurrency abstractions Gul Banana fucked around with this message at 07:52 on Jun 22, 2014 |
# ? Jun 22, 2014 07:46 |
|
redleader posted:Any chance you could elaborate on this? code:
I really am not sure why they chose having the factory being the primary part of the foreach loop and LINQ but it means that it's a pain in the rear end to handle delimited chunking efficiently (or as far as I can tell at least)
|
# ? Jun 22, 2014 12:47 |
|
I'm not even sure in what kind of nightmare land you'd want iterating over the same collection twice in a row to print two different results. IEnumerator is the iterator for IEnumerable. Iterators are mutable even when the enumerable isn't, which is why it makes no sense to expect any sort of consumer state to be encoded in the enumerable. foreach creates a new iterator (IEnumerator). If you want to use the same enumerator across multiple loops (i.e. for chunking), create it yourself before the loops and use the MoveNext method manually. edit: also for LINQ it wouldn't be that hard to write a collection wrapper that does chunking for you implementing IEnumerable. Volte fucked around with this message at 14:20 on Jun 22, 2014 |
# ? Jun 22, 2014 14:16 |
|
Volte posted:I'm not even sure in what kind of nightmare land you'd want iterating over the same collection twice in a row to print two different results. IEnumerator is the iterator for IEnumerable. Iterators are mutable even when the enumerable isn't, which is why it makes no sense to expect any sort of consumer state to be encoded in the enumerable. foreach creates a new iterator (IEnumerator). If you want to use the same enumerator across multiple loops (i.e. for chunking), create it yourself before the loops and use the MoveNext method manually. The factory-ness of ienumerable is fine, it's just that it doesn't make a lot of sense to iterate over a factory. I would rather you have to call GetEnumerator and then have to pass that enumerator to the foreach loop, to make the forcing explicit. The point is that the iterator encodes the current state. If you want to get another view of the collection, you call GetEnumerator which makes the "Reset" explicit. And then you make collections immutable like they ought to be
|
# ? Jun 22, 2014 15:44 |
|
Malcolm XML posted:The factory-ness of ienumerable is fine, it's just that it doesn't make a lot of sense to iterate over a factory. It's such an unusual situation to have to reuse an iterator over multiple loops that I don't see why just converting your foreach loops into regular for or while loops using explicit iterators is such a big deal. Also, C# code:
C# code:
|
# ? Jun 22, 2014 17:59 |
|
Ithaqua posted:Should I be using source control? Let's be clear about what you're saying here - TFS is free up to 5 developers until you have to purchase a support contract from some TFS consultant to figure out how to make it work.
|
# ? Jun 23, 2014 02:44 |
|
|
# ? May 3, 2024 01:55 |
|
Deus Rex posted:Let's be clear about what you're saying here - TFS is free up to 5 developers until you have to purchase a support contract from some TFS consultant to figure out how to make it work. No?
|
# ? Jun 23, 2014 03:06 |