Enforce TypeScript Functional Programming

As consistent readers of this blog are aware, I’ve fallen in love with Functional Programming.  But I also live in a primarily Angular/TypeScript world where some code is still Object Oriented and other code is more Functional in nature.  And while TypeScript lets you do some Functional things, I’ve found it hard to force functional concepts in TypeScript.  So, I’ve gone searching.  Wouldn’t it be great if there were some sort of flag you could set that said, “Hey compiler, I’m in ‘Functional’ mode now!”  And the compiler would make sure that you never used a conditional statement, never accessed hidden parameters, and never mutated state?

Well, I think I’ve figured out some of how to manage all of this using nothing more than TypeScript and some TSLint rules.

Photo credit: archer10 (Dennis) 99M Views via VisualHunt.com / CC BY-SA

Continue reading “Enforce TypeScript Functional Programming”

How to Implement Angular 2+ Routing

In the old world where all of our pages were on the server and every change on the client side required a full round trip to the server, each page was a unique URL on the server.  In the SPA world, we only load one “Page” from the server and the client takes care of making it look like we have moved from one page to another.

When done well, we can create pages that reuse existing content on the screen causing a minimal screen refresh while still allowing the user to link to a specific “Page” in our application.

These “Pages” are called “Routes”  As in, here is the route to some code I want to execute.

How to Implement Angular 2+ Routing
Photo via Visual Hunt

Continue reading “How to Implement Angular 2+ Routing”

How To Be an Awesome Programmer

It isn’t what you think.  Being an awesome programmer, or being awesome at anything has a lot less to do with any given topic: programming, boxing, writing.  It has a lot to do with being a healthy human.  So, the simple answer to the question of “How to be an awesome programmer” is simply, “be healthy.”

But what does healthy look like?

I really couldn’t tell you what got me started, but I’ve been reading an experimenting with Brain Hacks, Diet, Exercise, and Social Skills for over a year now.  Turns out, they are all related.

Now, most of my audience has less than 5 years of experience.  I can say that because most of the programming population has less than 5 years of experience, so I’m going on the assumption that the people who read this blog, are a small representation of the global population.  Many symptoms I will reference are going to be things you may not suffer with … yet.  If you fall in that group, think of this post as a letter from your older self.  I was young once too.  I remember, I thought I was immune to some of these issues and if I wasn’t, there wasn’t much I could do.

But we’ve learned SO much in the last 20 years.  Much of what we’ve thought was “normal” really isn’t.  We are just proverbial frogs in a pan of water being heated to death.

How To Be an Awesome Programmer
Photo via VisualHunt.com

Continue reading “How To Be an Awesome Programmer”

Upload an Image as a File in Angular

This past week, I needed to be able to upload an image in my application to the server as a file so that I could crop it and upload it.

Now, uploading an image that you pulled up using the file upload control is relatively straight forward.  But, in our case, the image we want to be able to upload didn’t always come from the user’s file system.  This causes two problems.

First, you can’t crop an image you retrieved from a different URL using the HTML Canvas because of Cross Origin restrictions and second, you can’t upload the file using the standard file upload mechanism because you didn’t get it from the file system.

Upload an Image as a File in Angular
Photo via Visual Hunt

Continue reading “Upload an Image as a File in Angular”

What If Unit Testing Wasn’t Necessary? #noTDD

I recently read (yet another) post proposing that TDD “doesn’t work” and that we shouldn’t use it, or should use it very little.  What was shocking about this article wasn’t the content, but the fact that it is hosted on a Microsoft site.

While I’m not entirely on board with throwing out TDD, the one thing I will agree to is that learning TDD is difficult.  I am also willing to admit that, to a large extent, TDD is broken.  If you’ve been following my post for a while, this SHOULD be shocking news.

And so, I’ve been thinking.  Maybe we’ve been asking the wrong question.  Maybe, instead of asking “How do we encourage people to implement TDD?”  We should be asking, “How do we make TDD either unnecessary, or trivial to implement?”

What If Unit Testing Wasn't Necessary? #noTDD
Photo credit: abraham.williams via VisualHunt.com / CC BY-SA

Continue reading “What If Unit Testing Wasn’t Necessary? #noTDD”