|
Is there a commonly used style guide for C#? I'm coming from Java, which is different, and there is no var. Using var when the type will be unclear to whoever reads through it seems wrong, but I'm open to being corrected.
|
# ? Mar 3, 2016 19:17 |
|
|
# ? May 20, 2024 02:43 |
|
22 Eargesplitten posted:Is there a commonly used style guide for C#? I'm coming from Java, which is different, and there is no var. Using var when the type will be unclear to whoever reads through it seems wrong, but I'm open to being corrected. Here's the style guide from the Microsoft .NET Core repository: https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md EDIT: Also the more verbose Framework Design Guidelines on MSDN: https://msdn.microsoft.com/en-us/library/ms229042.aspx
|
# ? Mar 3, 2016 19:35 |
|
Bognar posted:Here's the style guide from the Microsoft .NET Core repository: https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md Or from MSDN: https://msdn.microsoft.com/en-us/library/ff926074.aspx https://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx I just var pretty much everywhere. You can find out the type in a few seconds in the IDE, and it can make refactoring easier. Change an IEnumerable to a List in a method's return type? No need to change anything else.
|
# ? Mar 3, 2016 19:42 |
|
Calidus posted:I have a Solution that contains a MVC 5 project, a business logic project and DAL project. When I try use the MVC scaffolding with my entity frame work objects in my DAL project I keep getting “Object reference not set to an instance of an object.” The MVC project has a reference to my DAL project. I tried creating a test db context inside my MVC project and I got the same error. This is driving me up a wall. I am using VS2013. Encase anyone else runs into this terrible poo poo. I had to uninstall EF from all of my projects and after reinstalling it I error about missing meta data and being unable to find the CLR for a class. Turns out that classes mapping was messed up in my EDMX model. The really confusing part is that model wasn't even the one being used to created a controller and seemed to work when using it for LINQ and Lamda functions.
|
# ? Mar 4, 2016 00:01 |
|
Ithaqua posted:
I'm not a fan, I think it really impairs readability if it's not immediately obvious what you're assigning to your var (ie in cases like var = New Foo()), or in cases where you're not sure exactly what flavour of collection you're getting back but it doesn't matter too much, like the result of a LINQ query which you're going to further query. Imo, in the refactoring example you gave, if you didn't explicitly need any of the methods provided by IList/List, you should have been assigning the result of the method to an IEnumerable anyway, not a List. In which case it's just as easy to refactor it. And if you did use a method of List, then changing the return type is going to break your code anyway, so using var hasn't gained you much. E: Microsoft seems to agree - https://msdn.microsoft.com/en-gb/library/ff926074.aspx - see 'implicitly typed local variables'. chippy fucked around with this message at 00:54 on Mar 4, 2016 |
# ? Mar 4, 2016 00:46 |
|
xgalaxy posted:Jet Brains C# IDE is out for early access (aka beta). I'm excited to check it out. While running Visual Studio on OS X via parallels is an okay experience it would be nice to have something that offers a bit of a smoother ride performance wise. I hate MonoDevelop. I've used IntelliJ before and loved it for Java programming. I'm curious how this will play out in the long run. They've built it as a wrapper around calls to Resharper which seems a bit different from their normal IDE's.
|
# ? Mar 4, 2016 01:13 |
|
I use var as much as I can. It promotes, or should at least, better variable names. After all, I care about what this thing should be used for (intent), not really what it is (type). For example:code:
code:
code:
|
# ? Mar 4, 2016 02:23 |
|
Tabs are so much better than spaces. Discuss.
|
# ? Mar 4, 2016 08:11 |
|
I'm conflicted about var because I generally prefer explicit over implicit, but for some reason I'm ok with using var whenever possible, even though it admittedly makes things harder to read sometimes. A lot of the time you can avoid the whole problem by not having all that many variables to begin with. If I have a variable that's only used on the line directly below its assignment I often fold it into the next function call (unless it makes things totally unreadable). Maybe most people consider that even worse though.
|
# ? Mar 4, 2016 13:53 |
|
I tend to explicitly define my types when I'm working on "important" code. Within the inner inner loop of an important function, I want to be careful that I, and everyone else, know exactly which types are in play. If it's a ToString function meant to dump Trace data, var's fine. Everything in the middle, use your judgement.
|
# ? Mar 4, 2016 16:16 |
|
I'm trying to use a treeview control in VB. Are these things retarded or what? Consider the following: 1. I have about 30 items to add in, in 3 levels. I can add them in to where they show up properly. 2. Some of these items have the same display text; in particular, some of the root items have the same text as the second-level items contained in them. Sometimes there may be multiple items with the same text. 3. I need to find exactly which item a user clicks on. How can I do that? I can get the text on the selected node using treeView.SelectedNode.ToString() or TreeView.SelectedNode.Text, but that isn't much help since the text on some them is the same.*** If I try to use treeView.SelectedNode.Index, that works but it only gives me the root index. It says nothing about the upper levels. For example,,,,,, I have four items at the root level. If I set up a messagebox to show me the selectednode.index in the treeview's afterSelect event, all I can get it to show is a number of zero to 3--which corresponds to the ROOT of the item I am clicking on. I find LOTS of other people online asking this same question, and all the replies just say use either way above, that is not useful. Is there another way to do this with a treeview or not? It seems like nearly-worthless as it is (if you can only really get the selected index of the root items???); I am amazed that they would make this work only halfway. It draws a pretty picture, but,,,, it doesn't appear to function usefully. What I was imagining was that each node would have a index number into ONE zero-base index for ALL the nodes, that you could ask the control to give you--but I find no indication of that. ***I had thought of trying to use a short string of unique but non-printing characters in the node text after the real text; this would be a way to tell the nodes apart by text even when the apparent text was the same. Does it ignore non-printing characters?
|
# ? Mar 4, 2016 18:49 |
|
fsharpConf 2016 https://channel9.msdn.com/
|
# ? Mar 4, 2016 19:05 |
|
edmund745 posted:I'm trying to use a treeview control in VB. Are these things retarded or what? Yes. quote:***I had thought of trying to use a short string of unique but non-printing characters in the node text after the real text; this would be a way to tell the nodes apart by text even when the apparent text was the same. Does it ignore non-printing characters? If I recall correctly, they have a 'Tag' property (typed to Object) that you could use for this. e: Yep. https://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.tag(v=vs.110).aspx chippy fucked around with this message at 19:28 on Mar 4, 2016 |
# ? Mar 4, 2016 19:25 |
|
Entity Framework Question: What is the advantage of using EF Designer from Database apposed to Code First From Database?
|
# ? Mar 4, 2016 19:26 |
|
chippy posted:.... If I recall correctly, they have a 'Tag' property (typed to Object) that you could use for this. As you (I) put nodes into the treeview, I use a counter and store that in the tag property, as well as in the things that are being added. I don't know why they didn't just have a separate node# property that was a zero-base index for all the nodes, in the order that they were added. You may not always want that, but most of the time it would seem the thing to do...
|
# ? Mar 4, 2016 20:16 |
|
Bognar posted:Here's the style guide from the Microsoft .NET Core repository: https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md Edit: 22 Eargesplitten posted:Is there a commonly used style guide for C#? I'm coming from Java, which is different, and there is no var. Using var when the type will be unclear to whoever reads through it seems wrong, but I'm open to being corrected. C# code:
Inverness fucked around with this message at 20:42 on Mar 4, 2016 |
# ? Mar 4, 2016 20:39 |
|
They're pretty old but I mostly agree with what these pieces have to say on the use of var: https://blogs.msdn.microsoft.com/ericlippert/2011/04/20/uses-and-misuses-of-implicit-typing/ http://www.brad-smith.info/blog/archives/336
|
# ? Mar 4, 2016 21:10 |
|
This is basically the tabs v. spaces argument of the C# world, everyone's gonna have their own preference and you likely won't be able to change anyone's opinion. That said, I might as well add to it. I use var for literally everything, anywhere and everywhere. I have never once run into a situation where I thought "I don't know the type of this variable, man I wish they had written the type in the declaration." Instead, it's always "I don't know the type of this variable, guess I'll hover over it and wait half a second for the type to be displayed." If I did less work in an IDE and more reading code through an external tool like Github then maybe it would be different. To me, descriptive variable names are significantly more important than the type declaration. That will help your understanding everywhere that variable is used rather than just at the point of declaration. When you're working on that 500 line eldritch horror function (every codebase has one), you don't want to be jumping back and forth to look at declarations to figure out the types because the variable names don't give enough information.
|
# ? Mar 4, 2016 21:47 |
|
I guess since we are on the style talk right now... What does everyone have their right margin set to? And how do you prefer to wrap long lines? Do you prefer hard wrapping, soft wrapping, chopping? Or does it depend on if its a method, method call, etc? I kind of go back and forth on chopping vs hard wrapping and usually go with what looks best at that instance instead of a hard rule on this. I'm curious what other people do. I was in a code base at one point where they always chopped, regardless if it was a long line or not. So every method definition and every method call had its arguments chopped. xgalaxy fucked around with this message at 22:20 on Mar 4, 2016 |
# ? Mar 4, 2016 22:17 |
|
I hate soft wrapping - I think it just makes everything more confusing. I tend to hard wrap things if necessary but my tolerance for line length is higher than 80 characters, probably closer to 120. I keep VS open on an entire widescreen monitor and so do most of my coworkers, so I don't see a huge need to keep to a limit that was defined in low resolution 4x3 aspect ratio days - especially with how verbose idiomatic C# can be. ReSharper makes hard wrapping less of an annoyance since it tends to do it for you when place a semicolon - of course that in itself can be an annoyance depending on what you're doing. I have no idea what you mean by chopping. Bognar fucked around with this message at 22:39 on Mar 4, 2016 |
# ? Mar 4, 2016 22:36 |
|
Bognar posted:I have no idea what you mean by chopping. This is chopping: code:
xgalaxy fucked around with this message at 22:57 on Mar 4, 2016 |
# ? Mar 4, 2016 22:54 |
|
xgalaxy posted:I guess since we are on the style talk right now... I decided to try soft-wrapping recently and I like it. No more worrying about re-indenting and such, and argument lists are a pleasant unreadable jumble. But seriously they're readable, you just read them, I think that's one place where being all prim isn't really that useful, aside from promulgating an air of professionalism in the "broken windows" sense. Edit: And by soft-wrapping that applies to comments, too, and they're wrapped at the Nth character with no "word" wrap. Edit: Of course, you could imagine it interfering with the view of indentation, and it's probably bad in that situation, in which case take it easy and hard-wrap some lines. sarehu fucked around with this message at 23:11 on Mar 4, 2016 |
# ? Mar 4, 2016 23:08 |
|
Bognar posted:To me, descriptive variable names are significantly more important than the type declaration. That will help your understanding everywhere that variable is used rather than just at the point of declaration. When you're working on that 500 line eldritch horror function (every codebase has one), you don't want to be jumping back and forth to look at declarations to figure out the types because the variable names don't give enough information. I totally agree, but I'm not sure why it keeps coming up in relation to the var debate. I try and make my variable names nicely descriptive whether or not I'm using explicit typing.
|
# ? Mar 4, 2016 23:42 |
|
chippy posted:I totally agree, but I'm not sure why it keeps coming up in relation to the var debate. I try and make my variable names nicely descriptive whether or not I'm using explicit typing. Because the most commonly quoted reason that people don't use var (knowing the variable type at the point of declaration) is usually unnecessary if the variable is named properly. There's no reason you can't have both descriptive variable names and explicit typing, but the former mostly obviates the need for the latter.
|
# ? Mar 5, 2016 00:14 |
|
I am terrible hack who just writes ugly code than has ReSharper pretty it up for me.
|
# ? Mar 5, 2016 01:26 |
|
xgalaxy posted:This is chopping: I do this, but it's only because I hate it the least. I don't like it.
|
# ? Mar 5, 2016 04:58 |
|
Calidus posted:Entity Framework Question: What is the advantage of using EF Designer from Database apposed to Code First From Database? I'm going to presume you are using the strict literal sense of 'EF Designer from Database'(aka the project template name) - where you are functionally doing a Database-first approach - and not a designer-first to generate both code *and* DB. That being said, it sure is helpful if you already *have* a database set up and just need to hook EF into it?
|
# ? Mar 5, 2016 06:19 |
|
Cuntpunch posted:I'm going to presume you are using the strict literal sense of 'EF Designer from Database'(aka the project template name) - where you are functionally doing a Database-first approach - and not a designer-first to generate both code *and* DB. Yes if you already have your database and you want to hook EF into to, VS has two templates to do that. I am trying to figure out which one better suits my needs.
|
# ? Mar 5, 2016 06:56 |
|
code:
code:
code:
|
# ? Mar 5, 2016 11:48 |
|
In this thread?code:
|
# ? Mar 5, 2016 13:05 |
|
No unsafe keyword posted:In this thread?
|
# ? Mar 5, 2016 13:50 |
|
code:
|
# ? Mar 5, 2016 19:02 |
|
Maybe they're doing unsafe character pointer operations
|
# ? Mar 5, 2016 19:18 |
|
Is this an appropriate place to ask for help regarding Netduino or .NET Micro Framework 4.3? I just got a Netduino 3 Wifi but I'm struggling to find current and accurate documentation online and I'd like to move some servos and steppers.
|
# ? Mar 5, 2016 22:35 |
|
durtan posted:Is this an appropriate place to ask for help regarding Netduino or .NET Micro Framework 4.3? I just got a Netduino 3 Wifi but I'm struggling to find current and accurate documentation online and I'd like to move some servos and steppers. Either here or the embedded thread: http://forums.somethingawful.com/showthread.php?threadid=3500975 However, to my knowledge there aren't a whole lot of people working with the combination of .NET and embedded stuff so you might have trouble getting answers.
|
# ? Mar 6, 2016 20:49 |
|
Bognar posted:Either here or the embedded thread: http://forums.somethingawful.com/showthread.php?threadid=3500975 Cool, thanks!
|
# ? Mar 6, 2016 23:46 |
|
Calidus posted:Yes if you already have your database and you want to hook EF into to, VS has two templates to do that. I am trying to figure out which one better suits my needs. I don;t think anyone has answered you so here's my take: I use the Db first w/ EDMX designer and modify T4 templates because I do very little, if any, modifying beyond implementing an interface on the data model classes. I also never touch the EDMX designer except to "update from database". I also keep track of db changes in a seperate database project in my solution for posterity and I'll explain why... Changes to the production databases are usually done manually because, most if not all I deal with of any significant size all are still SQL 2008 or less, locked pretty tight, and spread across multiple instances. I keep track of any changes via the database project in the event it (for some reason) needs to be rebuilt or I need to spin up a new dev db. My application/solution itself never gets authority to make any db changes so, I just pull in changes from a dev or prod SQL server into the EDMX and also the DB project and pray. I'm not on the latest latest EF btw - in case something is new that I haven't seen yet.
|
# ? Mar 7, 2016 08:12 |
|
Database versioning is a bitch of a problem. Visual Studio has Schema Compare, so is there a way to do something like compare your shiny new database project to the production database and come up with a conversion script that brings the production database up to date with all the changes in the project? My experience is Schema Compare is mainly usable as a litmus test for whether your handwritten conversion script is good or not...it's very painful, especially because DBAs make changes that don't get back to any database project. Just comparing the new DB project with the DB project for your last production release does you no good.
|
# ? Mar 7, 2016 08:18 |
|
fleshweasel posted:Database versioning is a bitch of a problem. You can use sqlpackage.exe and/or the DAC Framework libraries to run your project's .DACPAC file against your production DB and generate a migration script and/or a pretty XML summary of the changes that will be applied, before you let it actually take care of the migration. You need to be dealing with SQL 2008R2 or higher (though in theory SQL2005+ can work with the right service packs). Windows XP is unsupported, but you can make it work as long as you install the right registry keys (I had to find a way to make it work because we had a few hundred XP machines still out there ). All in all it's not the most awesome thing ever but IMO it's a massive upgrade over any kind of manual migration tool. If you still need to do any hand-massaging you can include both pre- and post-deployment scripts as well.
|
# ? Mar 7, 2016 21:03 |
|
|
# ? May 20, 2024 02:43 |
|
Huh, Microsoft announced SQL Server for Linux today. Should be interesting to see how that plays out. I'm guessing they're targeting the people who want something better than MySQL but less expensive than Oracle.
|
# ? Mar 7, 2016 23:03 |