Quote:
Originally Posted by suzzer99
Thanks dude. A few general questions:
- What do you use for C# unit testing?
- Is there something like javadocs for C#?
- For #2 would it use those annotation thingies (the stuff in square brackets that live above classes and methods)? Are they often used for other stuff? One of our existing code examples uses them to drive a swagger-like API documentation. I do generally like the idea of annotation as semi-living code vs. formatted comments.
- Is using var considered bad practice?
- Does using VS Code for C#/.net development make any sense - or does it have to be Visual Studio?
For #5 - I really like serverless.com for AWS lambda development. It works with C# lambdas but kind of competes with the AWS SDK for Visual Studio. Unfortunately AWS SDK only works with VS on PC, not Mac. So I'd have to switch over to my clunky PC to use VS with the AWS SDK. So for now I'm just leaning toward VS Code but the other devs will keep using VS I'm sure.
Oh yeah, is there any way around this redundancy?
Code:
public class Response
{
public object Payload {get; set;}
public string Message {get; set;}
public bool IsError {get; set;}
public Response(object payload, string message, bool isError){
Payload = payload;
Message = message;
IsError = IsError;
}
}
You kids and your static typing I swear.
Also some of the examples I find seem to capitalize class variables (like this) and methods. But then some don't. Is there a convention?
1) There's no universally used solution. There's a comparison
here. I like the IDE-integrated one.
2) Yeah, you use XML. Details
here.
3) Yeah the annotations (they're called attributes) are nice. They're not used for the default documentation, but they are commonly used for other things. For example, if you're writing a REST API you annotate methods with [HttpPost] or [HttpGet], which should be self explanatory.
4) No. Opinions differ. I presume you know that var is just syntactic sugar - the variable is still typed, the compiler infers the type. Using actual untyped variables (with "dynamic") is frowned on.
Personally I avoid using var - the one time I use it is in ExtremelyLongTypeName x = new ExtremelyLongTypeName(); where if var is used you can still easily see what the type is reading the code. But Resharper (a VS addon which I recommend) by default has a style rule recommending the use of var, so like I said, opinions differ.
5) I haven't used VS Code yet so it's hard to say, but VS is pretty good.
6) You don't have to write a constructor if you don't want to, you can set properties with an initializer:
Code:
Response r = new Response { Payload = payload, Message = message, IsError = isError };
7) Classes, methods and properties are pascal cased. Private member variables are camel cased. Not sure about public variables because you shouldn't ever have any - expose them with properties.