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

12-06-2018 , 01:17 PM
@micro sorry didn't read that close enough, that looks really atrocious lol. Those kinds of side effects is a really bad idea and leads to tightly bound code. Functions should really only affect things in its own scope or return something useful.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 01:23 PM
Quote:
Originally Posted by Grue
@micro sorry didn't read that close enough, that looks really atrocious lol. Those kinds of side effects is a really bad idea and leads to tightly bound code. Functions should really only affect things in its own scope or return something useful.
So, I'll test this, but if the only thing that setFoo function is accomplishing is making the customer info available, what should really happen is it should be passed in as an argument when the pdfGenerator function is called instead, right?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 03:28 PM
Quote:
Originally Posted by Grue
Depends on what you're doing with pdf after that call.



In vanilla js typeof will work for all types other than null array and object. Array.isArray is basically "typeof array". Typically you can get away with process of elimination for objects.

The real question is why are you calling methods with variables you already don't know the type of?
The field can be like 5 different strings. I honestly don't see how it could be called with a different value than those. But we want to protect so that it's not called with an invalid value.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 03:38 PM
Quote:
Originally Posted by well named
Victor: If you create a type alias that's just 'one string' | 'another string', then the value of a variable set to that type is just going to be a string. Type aliases don't create any actual javascript code, they just tell the typescript compiler what you should be allowed to set. There is no instanceof or typeof because no actual code is generated in relation to the type alias.

But if you know it's either string a or string b at runtime you can just check for either:

if (myvar === 'string one' || myvar === 'string two') ...

(See type aliases and string literal types here: https://www.typescriptlang.org/docs/...ced-types.html)
Thanks. This makes sense. The problem is that there's like 8 different strings it could be and I wanted a concise way to write it without checking for all strings.

And @grue, yes my inclination would be to remove the if statement and just call it for reasons you mention and which are apparent in the code.

But there was already a check there (this is refactor) and the "doSomething" is calling an external api so protection isn't really bad.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 03:54 PM
At the top level I'd do if (!['a', 'b' etc].includes(arg)) return; or something.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 06:26 PM
Quote:
Originally Posted by Victor
The field can be like 5 different strings. I honestly don't see how it could be called with a different value than those. But we want to protect so that it's not called with an invalid value.
I don't fully understand I guess but this is exactly what typescript is doing for you with your type alias. If you pass any string not in the conditional type it should be a compiler error. It's possible you're not getting this because you didn't define the type on the function param
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 06:38 PM
As long as all the callers are typescript then it can't be called with an invalid value. But the checking is compile time, so if you interop with any javascript code that might call the method than it could pass something else.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 07:24 PM
Quote:
Originally Posted by well named
As long as all the callers are typescript then it can't be called with an invalid value. But the checking is compile time, so if you interop with any javascript code that might call the method than it could pass something else.
True but in that Case short of gross hacking you need to just check each case. I would argue using a string alias type with 8 options is probably getting into antipattern land anyways and should probably be an enum or the state pattern or interfaces or something
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 07:26 PM
Yeah I agree
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 08:17 PM
Quote:
Originally Posted by microbet
So, I'll test this, but if the only thing that setFoo function is accomplishing is making the customer info available, what should really happen is it should be passed in as an argument when the pdfGenerator function is called instead, right?
I finally got a chance to get back to this and it worked fine passing the customer info in as an argument. I'll still ask why he did it that way.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:03 PM
**** typescript man. I just don't see the value gained for the pain for jumping through all these hoops. I think I'm just fully converted to loose-typing, even after 10 years as a Java dev.

Trying to write super-simple write tests in C# was such a nightmare. I have to create interfaces, and override things - just because I can't call a random method on an unknown object - even in test mode. Then I write basically the same test in node in 5 minutes.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:11 PM
My work (major state university) just offered me full time (not until late Feb because my contract needs to be 6 months). Lol my boss brought me in the office and shut her door. I thought she was going to put me in the dog house for all the design disagreements we've been having lately.

For the first time in my life I'll have a defined benefit pension. I guess that means I stop paying social security? Unclear.

Doing the rough math it looks like if I stick it out for 5 years I get around 10% of my salary for life (or I think 10% of some max - currently $123k). If I hang around 10 years I get 25% or so. If I stay 15 years (until I'm 64) I get 40%+. And I assume I'd still get Social Security for all the years I paid in. That's gonna be hard to walk away from.

****. I wish I got over $1k/month for life every time I put in 5 years with a company. I'd be done retired.

Or I can choose a 401(k) where I pay 7% and they pay 8% (up to the IRS max). No thanks. I have that already and Trump is destroying my nest egg as we speak.

Last edited by suzzer99; 12-06-2018 at 10:20 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:17 PM
Quote:
Originally Posted by suzzer99
**** typescript man. I just don't see the value gained for the pain for jumping through all these hoops. I think I'm just fully converted to loose-typing, even after 10 years as a Java dev.

Trying to write super-simple write tests in C# was such a nightmare. I have to create interfaces, and override things - just because I can't call a random method on an unknown object - even in test mode. Then I write basically the same test in node in 5 minutes.
Type dynamic, dude. As long as getting a RuntimeBinderException qualifies as an acceptable test failure, it's appropriate to use it in tests.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:36 PM
I think it was the generics (yay we can pass objects around w/o having to know their type - how awesome! but types are still good because reasons) I really struggled with. Here's the guts of what I had to do:

Code:
   public class Handler
    {
        static AppFxClient BBClient;

        public Handler()

...

        // virtual so it can be overriden by test hander
        // ideally eventually will pull from a service class that can be overridden to return mock services with env vars
        public virtual IDataList<EmailInput, LookupOutput> getDataList(AppFxClient client, Guid callId) 
        {
            return new DataList<EmailInput, LookupOutput>(client, callId);            
        }
I had to create the IDataList interface, which MockDataList and DataList (original code) implement.

Interface is super simple (minus the generics, which took a long time to wrap my head around):

Code:
    public interface IDataList<InputsT, OutputsT>
        where OutputsT : new()
        where InputsT : class
    {
        Task<IEnumerable<OutputsT>> LoadAsync(InputsT inputs, DataListLoadOptions options);
    }

}
So the test handler extends the lambda handler and a testing interface and overrides the getDataList method:

Code:
    public class HandlerTest : Handler, ILambdaTest
    {
        // xunit tests
        [Fact]
        public async void SingleUserSuccessTest()
...

        // overridden from Handler
        // ideally eventually will pull from a service class that can be overridden to return mock services with env vars
        public override IDataList<EmailInput, LookupOutput> getDataList(AppFxClient client, Guid callId) 
        {
           var mockDataList = new MockDataList<EmailInput, LookupOutput>(client, callId);
           mockDataList.HandlerTest = this;
           return mockDataList;
        }
Lotta hoops man. Here's some code for a node test that passes a mock DB client to the handler (in regular code the handler takes a real DB client and doesn't know or care the difference):

Code:
const docClientMock = {
  put: function(params, callback) {
    if (params.Item.UserId === "test-user-already-added") callback(dupeUserErrorResponse);
    else callback(null, successResponse);
  }
};

describe('Tests index', function() {
  it('verifies successful response', function(done) {
    saveNewUser(newUser, docClientMock, (err, result) => {
      test.value(err).is(null);
      test.object({success:true}).is(result);
      done();
    });
  });
});
;
This must feel like cheating to you.

Last edited by suzzer99; 12-06-2018 at 10:46 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:54 PM
Quote:
Originally Posted by suzzer99
My work (major state university) just offered me full time (not until late Feb because my contract needs to be 6 months). Lol my boss brought me in the office and shut her door. I thought she was going to put me in the dog house for all the design disagreements we've been having lately.

For the first time in my life I'll have a defined benefit pension. I guess that means I stop paying social security? Unclear.

Doing the rough math it looks like if I stick it out for 5 years I get around 10% of my salary for life (or I think 10% of some max - currently $123k). If I hang around 10 years I get 25% or so. If I stay 15 years (until I'm 64) I get 40%+. And I assume I'd still get Social Security for all the years I paid in. That's gonna be hard to walk away from.

****. I wish I got over $1k/month for life every time I put in 5 years with a company. I'd be done retired.

Or I can choose a 401(k) where I pay 7% and they pay 8% (up to the IRS max). No thanks. I have that already and Trump is destroying my nest egg as we speak.
I asked my mom, and she’s definitely an old, and you don’t get out of SS because of a pension. Education is one of the few places left where you can get a good pension, do you have to join a union for it?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 10:58 PM
Quote:
Originally Posted by suzzer99
This must feel like cheating to you.
Not really, it looks a lot like Moq. You don't need to create a MockDataList class, you can create an instance of any interface you like and define behaviour on the fly, just like you've done in the Node example. The only extra code is writing the interface, which is a couple of clicks in the IDE to extract from the class.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:05 PM
We actually have a lot of spec for typescript written in plain javascript, but it's all front-end using karma-webpack so it's straightforward for a javascript test file to import a compiled typescript dependency.

For some angular 6 spec files in typescript we've been trying ts-mockito, and I like it so far.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:06 PM
Quote:
Originally Posted by ChrisV
Not really, it looks a lot like Moq. You don't need to create a MockDataList class, you can create an instance of any interface you like and define behaviour on the fly, just like you've done in the Node example. The only extra code is writing the interface, which is a couple of clicks in the IDE to extract from the class.
Ok cool - I will check it out. That's what I need. Does it work with generics?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:08 PM
Quote:
Originally Posted by kerowo
I asked my mom, and she’s definitely an old, and you don’t get out of SS because of a pension. Education is one of the few places left where you can get a good pension, do you have to join a union for it?
I know some govt employees either pay into SS or their pension but not both. Maybe just federal.

I definitely don't want out of SS benefits - assuming they still exist in 15 years. But if I hang around about 7 years roughly, this pension should match SS/month.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:20 PM
She worked for the FAA for a long time so I assumed she knows what shes talking about, but then she is old...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:28 PM
Quote:
Originally Posted by goofyballer
Base: current salary minus 60k
Bonus: 20k/yr (base; could be as high as 40k if I kick ass but I have no visibility into how easy or hard that is)
RSU: 140k, typical vest
Does 140k RSUs mean 35k/yr vest? Do you get additional grants every year on the order of $140k ?

That can't be treated like $140k today cash in your pocket, but it should be treated as worth a lot more than $35k you'll receive in a year. Suppose you work there for 8 years. You'll be collecting 4x25%=100% of RSUs in years 4-8. Seems like a much better offer than the other two if my assumptions are correct.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:48 PM
Defined benefit is awesome. Congrats!

In Canada, the only defined benefit plan I’m familiar with (which is obviously not the same as one in the US) you still pay the equivalent of Social Security and the pension contributions (yours and your employers) deduct from your 401k equivalent contribution limit.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:54 PM
Quote:
Originally Posted by maxtower
Does 140k RSUs mean 35k/yr vest? Do you get additional grants every year on the order of $140k ?



That can't be treated like $140k today cash in your pocket, but it should be treated as worth a lot more than $35k you'll receive in a year. Suppose you work there for 8 years. You'll be collecting 4x25%=100% of RSUs in years 4-8. Seems like a much better offer than the other two if my assumptions are correct.


My read is that that was 140 over 4 which is equivalent to 35k/year (adjusted however you want for stock volatility). Its very unlikely he’d be getting additional grants for 140k/year at the end of that. It’s more like he’d be getting another 35k/year of RSUs each year after (before any comp increase/promotion adjustments).

In some cases public RSUs can be less valuable than private RSUs because the private valuation can be much lower than what the public market would pay. Of course that’s obviously offset by the decreased liquidity and increased risk.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-06-2018 , 11:58 PM
I got a 2 on my 9 box today thats good right!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
12-07-2018 , 12:31 AM
Quote:
Originally Posted by suzzer99
Ok cool - I will check it out. That's what I need. Does it work with generics?
Yeah, it's pretty flexible. Moq is the one I have used and is easily the most popular .NET mocking framework. If you find something it can't do, there are others - NSubstitute and RhinoMocks are others that I know are things that exist. I have no idea what if anything they offer over and above Moq.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m