Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

10-24-2018 , 06:23 PM
Super noob c# question. Is there something like Javadocs for all the classes in .netcore 2.1? I've been googling and just going around in circles with "what's new" and "getting started" guides. I just want the full specification so I can browse the classes.

Even though the lambda C# docs say this should work:

Code:
using Amazon.Lambda.Core;
using System;

[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace AwsDotnetCsharp
{
  public class Handler
  {
    // using async example
    public async Task<Response> Hello(Request request, ILambdaContext context)
    {
      var response = await Task.Run(() => {
        LambdaLogger.Log("Test1");
        return new Response("Go Serverless v1.0! Your function executed successfully!", request);
      });
      return response;
    }
  }

...

 }
I'm getting these errors:

Quote:
... publish: Handler.cs(11,40): error CS1983: The return type of an async method must be void, Task or Task<T> [/lab/demo-csharp-lambda/aws-csharp.csproj]
... publish: Handler.cs(11,25): error CS0246: The type or namespace name 'Task<>' could not be found (are you missing a using directive or an assembly reference?) [/lab/demo-csharp-lambda/aws-csharp.csproj]
This seems useful but I can't figure out how to apply it: https://stackoverflow.com/questions/...d-not-be-found

dotnet --version on the command line yields 2.1.403

Here's my aws-chsarp.csproj:

Code:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AssemblyName>CsharpHandlers</AssemblyName>
    <PackageId>aws-csharp</PackageId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.2.0" />
  </ItemGroup>

</Project>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 06:36 PM
how would this be perceived?

I've written a bunch of scripts to do large-scale stress testing on our latest product in development. They take several hours to run. I don't really have anything else to do but watch them run and tweak configs if I see something going ****y.

I email my boss around 1:45 and say I'm going to go home and monitor these tests. That's acceptable right? I Know the assumption is if people say "working from home" that they're not going to do any work but these tests take 4-5 hours each and I'm running them in batches so I'd rather not just sit around in the office for my last 3 hours when I can just go home and watch sports and drink beer while I do exactly the same thing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 06:58 PM
Suzzer, it looks like you're just missing a using directive? put "using System.Threading.Tasks;" under the "using System;" line.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 07:02 PM
Quote:
Originally Posted by jmakin
how would this be perceived?

I've written a bunch of scripts to do large-scale stress testing on our latest product in development. They take several hours to run. I don't really have anything else to do but watch them run and tweak configs if I see something going ****y.

I email my boss around 1:45 and say I'm going to go home and monitor these tests. That's acceptable right? I Know the assumption is if people say "working from home" that they're not going to do any work but these tests take 4-5 hours each and I'm running them in batches so I'd rather not just sit around in the office for my last 3 hours when I can just go home and watch sports and drink beer while I do exactly the same thing.
Depends on if your company is process orient or results oriented. If its the former, they will probably see it as stealing time from the company. If it's the latter, you're still getting your work done so they probably won't care.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 07:13 PM
I found the problem. Added

Code:
using System.Threading.Tasks;
I tried using System.Threading.Tasks.Task - which didn't work obviously. Trying to remember this Java stuff from 10 years ago and translate it to C# is messy business.

Last edited by suzzer99; 10-24-2018 at 07:34 PM. Reason: Ponied by ChrisV! THANKS!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 07:21 PM
whats proper etiquette on renaming a fork of a project? I made significant changes and additions to a codebase but a lot of the core functionality remains the same. I was thinking of maybe isolating some of the original code in a folder with the original name.

the original author also put his name in some files using pythons __author__ var. This kind of annoys me. At what point do I delete that? lol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 09:57 PM
Quote:
Originally Posted by suzzer99
I found the problem. Added

Code:
using System.Threading.Tasks;
I tried using System.Threading.Tasks.Task - which didn't work obviously. Trying to remember this Java stuff from 10 years ago and translate it to C# is messy business.
By the way, for the meat of the framework - namespaces, classes, methods etc - you want the .NET API Browser, as none of that stuff is specific to C#. For C# syntax you want the C# Programming Guide.

Hit me up with any questions, it's the language I know best. I am sad on a daily basis that I have to write in Java instead at the moment. It's like having to write a novel in pidgin English.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-24-2018 , 10:25 PM
Quote:
Originally Posted by lostmypw
whats proper etiquette on renaming a fork of a project? I made significant changes and additions to a codebase but a lot of the core functionality remains the same. I was thinking of maybe isolating some of the original code in a folder with the original name.

the original author also put his name in some files using pythons __author__ var. This kind of annoys me. At what point do I delete that? lol
is it MIT/similar? if so do what you want and yeah rip out author nonsense if you want.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 03:31 PM
Wanted: a plugin for VS Code or Sublime that makes 4-space indents appear as 2 space indents to me. So the file is still 4-space, saves as 4-space, etc. But I see it as 2-space.

I don't know how you 4-space people don't go bananas with all the lost horizontal space and stuff running off the right side of the editor window.

And no we're not gonna use tabs instead of spaces because that never works - someone always mixes in spaces and screws everything up.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 03:38 PM
VIM
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 03:43 PM
Prettier will auto convert spaces to tabs and vice versa.

I was hardcore 4 space for a long time and yeah now 2 space and its just way better.

The obvious solution is be the lead and enforce your will on everyone btw
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 04:28 PM
3 space centrism.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 04:53 PM
Quote:
Originally Posted by Grue
Prettier will auto convert spaces to tabs and vice versa.

I was hardcore 4 space for a long time and yeah now 2 space and its just way better.

The obvious solution is be the lead and enforce your will on everyone btw
Yeah it's important to establish dominance early, like beating up the toughest guy in a prison yard. So I'll tell the two experienced C# devs that they have to start using 2-space indents, when pretty much every example on the web uses 4. That should establish me as the alpha dog.

Also the damn convention is curly brace on the next line. And the code lens by default in VS code makes a bunch of lines for itself. And the output/terminal window opens up below the code by default.

It's like the goal is to show as little actual code as possible in an ever-shrinking periscope view. I do not get it. I always want to see as much code as possible.

This is the big argument for indentation-based language btw. No wasted lines or characters, no arguments about curly braces or indention size (unless it's not 2). No curly brace matching hell. No space-wasting mario floating stairway ascii art when a bunch of nested curly braces close at the same time.

FWIW - my goal is not to convert the files but just make them appear to me as 2 space indents. So the flow would have to do something like convert all 4-space to 2-space while I view it, then convert it back when I save.

Last edited by suzzer99; 10-25-2018 at 04:59 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 05:39 PM
That seems like one of those very simple to explain and completely impossible to implement things.

It wouldn't surprise me if it took 5 seconds or 5 days.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 05:42 PM
We have extremely strict tabs only rules on our source and thank ****ing god for that. Anytime someone forgets it’s really irritating
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 05:46 PM
Yeah that's the point. Spaces always find their way in. At my previous jobs the JSPs were a horrible mess because it was a mix of tabs and spaces with devs who set their tabs to 2 or 4.

You should look into a mandatory linter that runs in everyone's dev environment and boinks out space indents before they can check it in. Or the next best thing is reject the pull request or commit if they don't pass the linter.

This is the only way I could see tabs-only working. But you have to be kind of nazi about it. I'm not going to be the new architect-guy enforcing that in people's work environments. And you always have to worry about re-enforcing your linter rules if platforms or environments change. It's a never ending job.

It seems a lot easier to just have a rule that all text editors and IDEs convert tabs to spaces. Devs seem to not have much trouble following that. And even if one fails, the first time another dev touches the file they get converted.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 06:05 PM
Quote:
Originally Posted by ChrisV
By the way, for the meat of the framework - namespaces, classes, methods etc - you want the .NET API Browser, as none of that stuff is specific to C#. For C# syntax you want the C# Programming Guide.

Hit me up with any questions, it's the language I know best. I am sad on a daily basis that I have to write in Java instead at the moment. It's like having to write a novel in pidgin English.
Thanks dude. A few general questions:
  1. What do you use for C# unit testing?
  2. Is there something like javadocs for C#?
  3. 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.
  4. Is using var considered bad practice?
  5. 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?

Last edited by suzzer99; 10-25-2018 at 06:17 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 06:16 PM
Use husky precommit to write all files with prettier before any can commit and get filthy spaces in your beautiful tab filled code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 06:41 PM
For C# testing here is some code that uses DataList, which is a class in our internal library specifically for accessing our back end CRM over SOAP.

Code:
DataList dataList = new DataList<EmailInput, LookupOutput>(crmClient, callId);

List<LookupOutput> results = await dataList.LoadAsync(new EmailInput("test@gmail.com"));
It seems like the best way to test was if I could somehow point DataList to another class - when in test mode only. Then that class could return mock data to the lambda handler. I guess dependency injection is the usual way to handle this. But the problem is I'm bound by AWS lambda to this method signature as the entry point to start operations:

Code:
public async Task<Response> LookupCrmUser(Request request, ILambdaContext context)
So there's no simple way I can see to inject a mock instance of DataList.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 07:11 PM
Suzzer,

Re: a couple posts ago, you can set properties at object initialization without having to define constructors, like this:

Code:
using System;

public class SaleItem
{
   public string Name 
   { get; set; }

   public decimal Price
   { get; set; }
}

class Program
{
   static void Main(string[] args)
   {
      var item = new SaleItem{ Name = "Shoes", Price = 19.95m };
      Console.WriteLine($"{item.Name}: sells for {item.Price:C2}");
   }
}
// The example displays output like the following:
//       Shoes: sells for $19.95
Ref: https://docs.microsoft.com/en-us/dot...cts/properties
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 07:17 PM
Gotcha - thanks.

I guess the reason my example started off with this is for constructors that are automatically being called by lambda deserializing JSON. But actually it looks like as long as I name my member variables the same as the json properties - I don't need a constructor there either.

Last edited by suzzer99; 10-25-2018 at 07:23 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 07:36 PM
Quote:
Originally Posted by suzzer99
Thanks dude. A few general questions:
  1. What do you use for C# unit testing?
  2. Is there something like javadocs for C#?
  3. 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.
  4. Is using var considered bad practice?
  5. 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.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 07:59 PM
Oh if you haven't seen it, I think as a dynamic types guy you'll like anonymous types. If you just wanted an object with the properties as in Response, you don't need to create a type if you don't want to:

Code:
var x = new { Payload = payload, Message = message, IsError = isError };
This is also syntactic sugar - that is a typed variable but the type doesn't yet have a name, the compiler creates a name for it at compile time. Anonymous types are really frequently used when using LINQ, C#'s functional programming implementation. You might do something like take a list of data, do a reduce on it into an anonymous type, convert it to JSON and return it to an API method. Cuts down on boilerplate.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 09:32 PM
Quote:
Originally Posted by suzzer99
FWIW - my goal is not to convert the files but just make them appear to me as 2 space indents. So the flow would have to do something like convert all 4-space to 2-space while I view it, then convert it back when I save.
Both emacs and vi can do this. I used to work some place where different projects had different standards. They used one of those comment-config-string things to say what the current file should use and we set our editors to act accordingly.

I think 2 vs 4 matters a lot more for languages where there's a lot of depth, like javascript. It's rare for me to be more than 2-3 levels deep and I code with wide files, I can't remember if it's 120 or 150. One of the devs on my team likes 80-char and I haaaaate it.

I used to code in 80-char wide files. Back when my display was 80 chars wide.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-25-2018 , 09:41 PM
Ah the sheer joy of shell-scripting. TIL that this works:

Code:
if [ "$failed" = "0" ]; then
while this:

Code:
if ["$failed" = "0"]; then
Fails and says "command not found". I mean duh that's just common sense.

But here's the really fun part.This always evaluates to true no matter what values $failed has:

Code:
if [ "$failed"="0" ]; then
Apparently, much like the spaces inside the square brackets, those spaces around the equal sign are very important! Argh - that was a fun hour of my life. Like were the designers of Unix just trolling everybody with this ****?

The great part is if I actually figure out how to do what I'm trying to do, I have to replicate it all over again in windows. Time to abort.

Last edited by suzzer99; 10-25-2018 at 09:47 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m