|
I realize this is , but does anyone have any strong opinions on commenting style for ASP.NET MVC Controller Action header comments specifically? For example, I have an action: C# code:
Please don't fight with each other over this. I'm less interested in the "right way" as I am just learning what other people do in these situations. Che Delilas fucked around with this message at 00:38 on Nov 29, 2014 |
# ? Nov 29, 2014 00:35 |
|
|
# ? May 15, 2024 21:08 |
|
Che Delilas posted:What information should I be adding in the header comments? I wouldn't put in a comment at all in that case. What needs explaining?
|
# ? Nov 29, 2014 00:54 |
|
Dromio posted:I wouldn't put in a comment at all in that case. What needs explaining? Agreed. Don't add comments that are useless like "pull data from db using id". The code itself should be enough in those cases. I add comments where the why of what I'm doing might not be clear
|
# ? Nov 29, 2014 01:02 |
|
Any time you feel like you have to write a comment to explain your code, it means you need to re-write your code. (Or you're doing something that makes absolutely no logical sense because there's a framework bug you have to deal with or something)
|
# ? Nov 29, 2014 05:11 |
|
I write comments for the invariants in my code - loop invariants, termination proofs, object state invariants, concurrency/async-reentrancy invariants - because they're the only really important thing about my code, and they're never straightforwardly implied or justified by the code itself. In the case of ASP.NET WebAPIs, I also write in comment an example http request (usually just the Uri) and a sample response. This example is present in unit tests but I like to have it closer to the code. I think it's crucial to always ground ourselves in the raw messages that get sent over the wire, not just in higher level abstractions of them.
|
# ? Nov 29, 2014 06:21 |
|
Funking Giblet posted:I think you're missing something major! You can validate the configuration at runtime which will find unmapped fields, or write a unit test to do as much. Not to mention injectable value and type resolvers which can be reused across types. I guess I haven't seen it work out simpler in the long run (though I've only really seen it used extensively twice), but if it works for you great.
|
# ? Nov 29, 2014 07:01 |
|
Is it just me or is a lot of the .Net documentation a bit poo poo? I want to learn about the different ways to render links with razer. So I end up here. http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions_methods(v=vs.118).aspx As a learning tool thats bloody awful. Where do you guys go to learn about the small things? I seem to just bounce around the web looking for examples.
|
# ? Nov 29, 2014 07:37 |
|
Dietrich posted:Any time you feel like you have to write a comment to explain your code, it means you need to re-write your code. Overcommenting is terrible, and a code style that "documents" itself well is important, but it's too much to say that good code never warrants comments.
|
# ? Nov 29, 2014 08:34 |
|
Destroyenator posted:Yeah I've seen the validation as unit tests thing, but the places I've seen it usually involve writing a bunch of exceptions for the missing/extra/renamed fields. That's when I get to: why bother, you're effectively writing the maps anyway at this point? Mapper.AssertConfigurationIsValid is all you need.
|
# ? Nov 29, 2014 09:07 |
|
bpower posted:http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions_methods(v=vs.118).aspx Stackoverflow is usually pretty good, though they close "best practices" or opinion questions; they're not interested in discussion. Codeproject can have some decent tutorials. Don't expect them to be up-to-date on everything, but they can be a good overview and starting point. Usually googling your specific issue or question will get you something from one or both of those sites first thing.
|
# ? Nov 29, 2014 11:22 |
|
fleshweasel posted:Overcommenting is terrible, and a code style that "documents" itself well is important, but it's too much to say that good code never warrants comments. I didn't say that, though.
|
# ? Nov 29, 2014 14:36 |
|
Thanks guys, got some good viewpoints.
|
# ? Nov 30, 2014 00:05 |
|
Dietrich posted:Any time you feel like you have to write a comment to explain your code, it means you need to re-write your code. I mean.... that's an OK rule of thumb, but that's not really true, entirely. Che Delilas posted:Stackoverflow is usually pretty good, though they close "best practices" or opinion questions; they're not interested in discussion. Codeproject can have some decent tutorials. Don't expect them to be up-to-date on everything, but they can be a good overview and starting point. Usually googling your specific issue or question will get you something from one or both of those sites first thing. Programmers.SE is a bit more in that direction.
|
# ? Nov 30, 2014 17:07 |
|
Che Delilas posted:I realize this is , but does anyone have any strong opinions on commenting style for ASP.NET MVC Controller Action header comments specifically? If you must: C# code:
|
# ? Dec 1, 2014 12:42 |
|
UnhappyEggWhisk posted:If you must: And, really, you mustn't.
|
# ? Dec 1, 2014 16:08 |
|
fleshweasel posted:Overcommenting is terrible, and a code style that "documents" itself well is important, but it's too much to say that good code never warrants comments. I want to emphasize here that while in .NET land code is often readable all on its own and this principle applies, this should not be taken as general-purpose programming advice. You might one day work in a horrifying language where you forget what your own code does the day after you write it because even the most basic expressions are horrifying. Please, please comment to your heart's content if you ever reach such a day.
|
# ? Dec 1, 2014 16:39 |
|
Why the hell is Random.Next() not thread safe?
|
# ? Dec 1, 2014 16:49 |
|
Newf posted:In favor of the css white-space: nowrap? What's the advantage? That is one way though there are a number of CSS techniques one could use (ie -- min width) to get there. The advantage is that you are no longer jamming presentation elements (HTML nonbreaking spaces) into your code and it is overall cleaner and easy to manage long term and it is doing the right thing.
|
# ? Dec 1, 2014 19:15 |
|
Hey, just looking for a couple different opinions here. At my annual review, one of the goals in the next year (in line with me taking more of a leadership role here) is to start actually implementing a peer code review process, and I'm wondering how any of you that have more formalized processes go through with it? e: v Exactly the type of answer I was looking for! Although 1 and 2 will be hard to implement currently as I am also in charge of ramping up the unit testing enforcement as well. We are (again, slowly) migrating over to TFS, but we still have some old stuff using SVN aBagorn fucked around with this message at 19:46 on Dec 1, 2014 |
# ? Dec 1, 2014 19:27 |
|
aBagorn posted:Hey, just looking for a couple different opinions here. At my annual review, one of the goals in the next year (in line with me taking more of a leadership role here) is to start actually implementing a peer code review process, and I'm wondering how any of you that have more formalized processes go through with it? 1) do unit tests pass? 2) look at new unit tests 3) look at code for any obvious architectural / readability problems 4) compiles with no warnings or code analysis violations Code review is not to validate functionality If you're using tfs 2012 or later, the code review feature makes this easier to manage and audit and can be enforced as a requirement before checkin. If you're using git, use a pull request for the same basic idea.
|
# ? Dec 1, 2014 19:43 |
|
Dietrich posted:Why the hell is Random.Next() not thread safe? I'm assuming because Random is from old .NET and the C# devs chose performance over thread safety, and because locking before calling .Next is easy if you need it.
|
# ? Dec 1, 2014 19:54 |
|
Try to get the responsibility for reviews to be shared by the whole team. You don't want to end up as a "gatekeeper" or seen as a blocker to code getting to production. The team should be responsible for code quality. In reviews just make sure you aren't too hard (especially early on). You're looking for acceptable not perfect. Even if no code is changed as a result of reviews you'll be getting benefits from better visibility of the code base and what your colleagues are doing day-to-day.
|
# ? Dec 2, 2014 06:00 |
|
Dietrich posted:Why the hell is Random.Next() not thread safe? because it mutates state..? exact same reason that globalPreviousRandomNumber = currentRandomNumber; wouldn't be.
|
# ? Dec 2, 2014 07:00 |
|
Bognar posted:And, really, you mustn't. Yeah I mean, that's the obvious "function header comment just to have one" type of comment. I couldn't think of anything novel to put there, especially since it's for a Controller class and not a library I'm going to distribute or something. Good to know I don't really need to bother in cases like that.
|
# ? Dec 2, 2014 11:25 |
|
Gul Banana posted:because it mutates state..? exact same reason that Java's Random is thread-safe by default. Just because you mutate internal state doesn't mean you can't lock while doing so.
|
# ? Dec 2, 2014 16:00 |
|
Java also provides "thread safe" versions of their collections
|
# ? Dec 2, 2014 16:43 |
|
Entity Framework question about nullable Guids in the db. I have the following table with 3 Guids. ReportsToId is nullable CREATE TABLE [dbo].Person]( [PersonId] [uniqueidentifier] NOT NULL, [ReportsToId] [uniqueidentifier] NULL, [BusinessId] [uniqueidentifier] NOT NULL) When I get a new Person from the front end the ReportsToId might be an actual Guid or the Empty "0000000000-0000000-0000" . var p = PersonFromFrontEnd(); db.People.Add(p); db.SaveChanges; This runs insert into person([PersonId] , [ReportsToId] , [BusinessId] ) values ('454656-56465476-7789','000000-0000000000-0000000','566775765-756698698-57765') When I actually want insert into person([PersonId] , [ReportsToId] , [BusinessId] ) values ('454656-56465476-7789',null,'566775765-756698698-57765') Or insert into person([PersonId] , [BusinessId] ) values ('454656-56465476-7789','566775765-756698698-57765') How can I do this?
|
# ? Dec 3, 2014 21:37 |
|
It should work if you define the property as a nullable Guid, but you'd have to manually set it to null if you have an empty one. Don't know if there's some kind of mapping you could do in EF.code:
|
# ? Dec 3, 2014 22:12 |
|
bpower posted:When I get a new Person from the front end the ReportsToId might be an actual Guid or the Empty "0000000000-0000000-0000" . Either fix your front-end or explicitly check for Guid.Empty and replace with null.
|
# ? Dec 3, 2014 22:28 |
|
Thanks guys. I dont know why I didn't do that already. Brain freeze I guess.
|
# ? Dec 3, 2014 22:37 |
|
wwb posted:That is one way though there are a number of CSS techniques one could use (ie -- min width) to get there. NBSPs still has perfectly legitimate uses, though. Take the surname 'von Neumann' for example. That could be considered one token and to express that to a browser which differentiates between breaking and non-breaking spaces you'd send 'von Neumann'. That's not mashing presentation into 'code', it's correctly representing information. I'm not arguing for using NBSPs to pad content or whatever, but I don't think using them to tell the browser that "this string of characters is one thing; treat it as such" is wrong or bad or whatever.
|
# ? Dec 4, 2014 07:03 |
|
Dumb question but you guys are my go-to for dumb questions. I'm building a List (of String), and I want to check if something is already in the list before adding it. However what I'm not sure of, does the .Contains method match any part of any string in the list, or only entire items? So for example if the list is currently: code:
|
# ? Dec 5, 2014 02:38 |
|
Scaramouche posted:Dumb question but you guys are my go-to for dumb questions. Just checked the docs; quote:This method determines equality by using the default equality comparer, as defined by the object's implementation of the IEquatable<T>.Equals method for T (the type of values in the list). Which is what I thought. So it just calls .Equals (==) for each of them, so unless "diamond" == "black-diamond" returns true then it's not gonna match. Docs are handy!
|
# ? Dec 5, 2014 02:42 |
|
Scaramouche posted:Dumb question but you guys are my go-to for dumb questions. It's an exact match. Think of it like this: List<T> accepts any object. If I had a List<Customer>, what would a partial match of a customer be? It just checks for reference equality. If you need a partial match, you could do list.Any(l => l.Contains("diamond"); Of course, keep in mind that's case sensitive.
|
# ? Dec 5, 2014 02:45 |
|
Scaramouche posted:Dumb question but you guys are my go-to for dumb questions. Dotnetfiddle.net is a handy place to bang out little test snippets when creating a new project doesn't seem worth the hassle.
|
# ? Dec 5, 2014 03:42 |
|
Hah, thanks guys. I'm working off of mobile hotspot while switching broadband providers and my first Googling didn't give me what I wanted so I figured it'd be faster to ask here rather than wait 10 seconds for each page load. Newf: That looks ideal, will have to see how it handles low bandwidth usage. EDIT-In retrospect it feels like I'm spending more time checking if the list contains things than actually inserting into it. Might switch to hashset Scaramouche fucked around with this message at 05:52 on Dec 5, 2014 |
# ? Dec 5, 2014 05:49 |
|
Scaramouche posted:Dumb question but you guys are my go-to for dumb questions. If you don't want duplicates a Set might be better.
|
# ? Dec 5, 2014 09:12 |
|
New MSDN blog post: Introducing .NET Core. That's pretty interesting. I was just reading the Reddit thread on it and saw a comment about AppDomains from a dev: quote:There are no AppDomains in .NET Core (nor any other .NET platform that we've released since .NET Framework itself). AppDomains add a significant overhead/complexity to the runtime, and are not what we internally call "pay for play". That is, regardless if you use them or not, AppDomains result in a ~5% overhead for all apps. For example, in mscorlib (which is domain neutral, and is loaded once for all AppDomains), every static field access requires an extra indirection. AppDomains made sense back in v1 of .NET, where sandboxing and isolation was a goal. In recent years however, partial trust is no longer guaranteed.
|
# ? Dec 5, 2014 14:25 |
|
Design question! I currently have a project (in the baby stages) that has this basic setup Ember JS Web API 2 Service/Business Logic Layer Entity Framework I've obviously been trying to keep EF model objects away from my Web API layer, but when trying to flatten everything into nice DTOs for Ember JS, it's becoming increasingly annoying to do so. Should I be flattening in the service layer? I am mainly using that for data access and some calculations that need to be done before objects are saved to the DB. I had been serializing to JSON at that layer and passing up to the Web API in that format and had hoped to just pass that right along to ember without touching it, but based on the requirements of the views, that is no longer an option (the relationships between the classes are all many to many due to needing historical data, and the view only needs to grab the current relationship). Forgive me if I'm explaining this incorrectly.
|
# ? Dec 5, 2014 14:41 |
|
|
# ? May 15, 2024 21:08 |
|
After a while of Googling, I haven't been able to get a clear answer on whether QPC() measures CPU time or actual time. I need an operation to occur every 100ms, so I need actual time. If not QPC(), what should I use? I'm stuck in MFC or WINAPI land. Maybe the wrong thread, but it was the closest I could find. I don't want to type the actual function name on my phone.
|
# ? Dec 5, 2014 14:58 |