Brent Lewis – The uShip Blog https://ushipblogsubd.wpengine.com Tue, 24 Apr 2018 18:51:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 JavaScript for C# Developers https://ushipblogsubd.wpengine.com/shipping-code/javascript-for-csharp-developers/ https://ushipblogsubd.wpengine.com/shipping-code/javascript-for-csharp-developers/#comments Thu, 17 Mar 2016 14:45:48 +0000 https://ushipblogsubd.wpengine.com/?p=4285 Overheard at work today: “…this is why I hate JavaScript so much.” Sound like something you’d say? Instead of letting the hate flow through you, know that it doesn’t have to be like that. JavaScript is evolving quickly and picking up luxuries that C# has had for years. Subtle Differences Before I get into the... Read More

The post JavaScript for C# Developers appeared first on The uShip Blog.

]]>

Overheard at work today:

“…this is why I hate JavaScript so much.”

Sound like something you’d say? Instead of letting the hate flow through you, know that it doesn’t have to be like that. JavaScript is evolving quickly and picking up luxuries that C# has had for years.

Subtle Differences

Before I get into the cooler, newer parts of JavaScript, a few key differences from C# that you should really know about:

  • Equality checking. Use triple equals (===) for common, everyday equality checking (or !== for inequality). Avoid double equals (==) due to some hidden gotchas.
  • Variable declarations. Variables instantiated with var do not behave how you expect. They’re lexically scoped as opposed to the block scoping of C# and most other languages. e.g. vars created inside of for loops and if blocks are visible beyond the curly braces. The 2015 edition introduces let, which works like C#’s var.

Language Features

JavaScript went several years between editions: the third edition was released in 1999, the fifth edition in 2009. Not anymore – the sixth edition was published June 2015 and included a proposal for two-year release cycles. Some of the new features include:

    • LINQ. Code written with LINQ is generally more declarative and expressive than code that isn’t, and it’s easily within reach when writing JS. Similar functions for arrays exist in JS, they’re just named differently:
      • map instead of Select
      • filter instead of Where
      • sort instead of OrderBy
// C#
var philly = new MenuItem("philly", "fries", 10.99m);
var reuben = new MenuItem("reuben", "fries", 9.99m);
var pizza = new MenuItem("pizza", "salad", 16.99m);
var menu = new [] { philly, reuben, pizza };

var choices = menu
   .Where(x => x.Side == "fries")
   .OrderBy(x => x.Price)
   .Select(x => x.Name);

// choices => ["reuben", "philly"]
// JS
var philly = { name: "philly", side: "fries", price: 10.99 }
var reuben = { name: "reuben", side: "fries", price: 9.99 }
var pizza = { name: "pizza", side: "salad", price: 16.99 }
var menu = [philly, reuben, pizza];

var choices = menu
   .filter(x => x.side === "fries")
   .sort((x, y) => x.price > y.price)
   .map(x => x.name);

// choices => ["reuben", "philly"]
    • Class syntax. Introduced in ES6, the class syntax makes creating classes look much more familiar to the usual C# style. There are still fundamental differences in how inheritance works in JS vs. C#, but a similar syntax will help smooth some of that over.
// C#
class Address {
    private readonly string _city;
    private readonly string _state;
    private readonly string _zip;

    public Address(string city, string state, string zip) {
        _city = city;
        _state = state;
        _zip = zip;
    }

    public string ToFormattedString() { 
        return _city + ", " + _state + " " + _zip;
    }
}
// JS
class Address {
    constructor(city, state, zip) {
        this.city = city;
        this.state = state;
        this.zip = zip;
    }

    toFormattedString() {
        return this.city + ", " + this.state + " " + this.zip;
    }
}
    • String interpolation. JavaScript’s version of string interpolation uses backtick (`) characters. Must be using ES6 or later. Use it like so:
// C#
var number = 3;
var size = "large";
return $"I'll take {number} {size} pizzas, please";
// JS
var number = 3;
var size = "large";
return `I'll take ${number} ${size} pizzas, please`;

Development Environment

Both the development environment and tools that are available to you for a given language greatly affect your productivity and experience for that language, irrespective of the language itself. Visual Studio, despite being a bit sluggish at times, is a great development environment to work in. Popular JavaScript IDEs tend to be less IDE and more text editor, which makes them feel quicker and more responsive.

  • Powerful IDE with community plugins. What makes VS even better is the plugin ecosystem, ranging from the essential ReSharper to the tiny Hide Main Menu (personal favorite). For JavaScript, Sublime is hugely popular, and more recently Atom by GitHub, which both offer a fantastic set of user-created packages and themes. There’s also the lightweight Visual Studio Code, which supports both C# and JS!
  • ReSharper-style suggestions. Even though JavaScript is an interpreted language, front end developers have recognized the value in catching potential errors before execution. In Sublime, adding the SublimeLinter package (plus a little bit of configuration) gives you static code analysis à la ReSharper. Examples include removing unused variables, removing unreachable code, and requiring a default case in switch statements.
  • Importing. Gone are the days where you have to include a multitude of scripts on the page in a particular order. Just like in statically typed languages like C#, you can use import statements in your JS files to reference other files, which are then built with a tool like webpack or Browserify. Throw NodeRequirer into the mix, an Intellisense-like plugin for Sublime for finding files, and you’ll feel right at home.
  • Package manager. NuGet is handy, but npm is handier.

Testing

JavaScript development is a wild west of roughly thrown together code, with undefined is not a function hiding under every rock, right? Wrong!

    • Unit testing. Popular testing frameworks include Jest and Mocha, with Karma as a kickass test runner – it even has the ability to rerun the test suite when a .js file changes! Test-driven development is popular in .NET communities, and JS developers are starting to embrace it – for example, this Redux tutorial is written in TDD style.
// C#
[Test]
public void Should_return_true_for_valid_prime_number()
{
   var isPrime = _classUnderTest.IsPrimeNumber(37);
   isPrime.Should().Be(true);
}
// JS
describe("isPrimeNumber", function () {
    it("should return true for valid prime number", function () {
        var isPrime = isPrimeNumber(37);
        expect(isPrime).to.be(true);
    });
});

Server-side

Historically, JavaScript has always been known as a client-side language, but node.js has completely changed that notion.

    • Server / API frameworks. With the addition of a middleware layer like Express or Hapi, you can quickly write robust, fully-featured server and API code.
// C#
public class SandwichesController : ApiController
{
   public ActionResult Index(int id)
   {
       // do stuff with the request and response
   }
}
// JS
var express = require("express");
var app = express();

app.get("/v2/sandwiches/:id", function (request, response) {
   var sandwichId = request.params.id;
   // do stuff with the request and response
}

Conclusion

JavaScript isn’t so bad, right?

Originally posted on the author’s personal blog.

The post JavaScript for C# Developers appeared first on The uShip Blog.

]]>
https://ushipblogsubd.wpengine.com/shipping-code/javascript-for-csharp-developers/feed/ 1
You Should Attend A Tech Conference https://ushipblogsubd.wpengine.com/tips/you-should-attend-a-tech-conference/ https://ushipblogsubd.wpengine.com/tips/you-should-attend-a-tech-conference/#respond Thu, 17 Sep 2015 10:06:19 +0000 https://ushipblogsubd.wpengine.com/?p=4185 Introduction Tech conferences are a great way to learn and be inspired. The following describes a few tips to know beforehand. Finding and Booking Conferences First, identify what you are looking to get out of a conference, which languages or frameworks you’re interested in, if you want to travel or not, and date availability. Not... Read More

The post You Should Attend A Tech Conference appeared first on The uShip Blog.

]]>
Introduction

Tech conferences are a great way to learn and be inspired. The following describes a few tips to know beforehand.

Finding and Booking Conferences

First, identify what you are looking to get out of a conference, which languages or frameworks you’re interested in, if you want to travel or not, and date availability. Not sure where to find potential conferences? You have several options:

  • lanyrd.com
  • meetup.com
  • Local tech meetups – often the same people attending or organizing meetups are the ones attending or organizing conferences

Second, consider your professional training budget – will your employer pay for it? If so, understand what will be required of you in terms of accommodations, budget, and receipts.  Here at uShip, developers are encouraged to attend conferences, with a generous budget provided by management.  Stipulations include booking travel and accommodations through a specific site, and digitizing receipts afterwards, but it’s well worth it.

Finally, act quickly when you decide you want to go! Good conferences are just like good concerts or music festivals – if you wait until the last minute to buy tickets to Austin City Limits you’re going to miss out. I’ve made the mistake of waiting to buy a ticket for CSS Conf in New Orleans, and it sold out the next day when I attempted to finally buy a ticket.

 

Pre-Conference Planning/Checklist

Laptop – sounds obvious, but at the same time, I’d suggest only using your laptop in between talks or during lunch; more on that later. A backpack comes in handy here, especially for any swag.

Bring a paper notebook – there have been [studies] about better retention when writing something compared to typing or nothing at all.

A convenient tech conference virtual machine based on Ubuntu is Juicebox, which comes preloaded with commonly-used and talked about technologies like git, Python, Node, Ruby, and more.

Often times the schedule is not available at time of ticket purchase, but once the schedule is released, you should start thinking about which talks you’d like to attend. Some conferences do not offer a choice, which makes planning easier. Typically in your welcome packet you’ll receive a paper schedule or the schedule on the website will be accessible from your phone. Another parallel to music festivals here – you might have to make some tough scheduling decisions!

 

During the Conference

Be wary of falling into the boring classroom lecture trap – these aren’t required English composition college classes, so make an effort to get your time and money’s worth by paying attention*. I find my laptop, phone, and smartwatch to be distractions during talks – try to keep them put away during presentation. You hated the guy in class who was constantly asking questions, but again, try and make each talk as worthwhile to you as possible – and that means asking questions when you don’t understand or if you’re interested in learning more about a particular concept. Typically questions are welcomed at the end, time permitting, but is not always guaranteed unfortunately. Worst case, if you’d like more questions answered try to get the speaker’s contact information.

If during a talk you hear or see something really interesting, post about it on Twitter! Make sure to tag it with the conference name and/or relevant technologies (ex. #txjs #reactjs). You’ll help your personal brand in the tech world, and it’s another way to connect with other conference goers. The note will also be there for future reference if needed (your tweet might be a potential blog post).

* Some special tech conferences have a format that directly contradicts this, where they actively encourage attendees to leave talks as soon as they realize it’s not something they’re interested in. Check out what OpenSpace Conferences calls the ‘Law of Two Feet’.

 

Post-Conference

Just because the conference is officially over doesn’t mean you have to immediately forget everything. Type up any notes you have and publish them to your team. Even better, write a blog post to share with the world. Right after the conference is over is also a good time to checkout any new technologies or frameworks you were exposed to. If the conference organizer solicits feedback via survey, fill it out to help make that conference even better next year!

 

My Experiences

I’ve been to two tech conferences, and they differed quite a bit. Key points:

Nodevember

  • Venue: Nashville School of Law, Nashville, TN
  • Format:
    • Saturday and Sunday – didn’t have to miss any work (besides travel time)
    • Opening and closing keynotes (lasted over an hour!) – Quite inspiring, though did feel long at times.
    • Choice of 3 different talks in every timeslot (45 minutes) – Nice to have options and personalize your schedule.
  • Pros:
    • Catered lunch – Nothing mind blowing, but convenient.
    • Lots of swag – shirt, stickers, notebook, authored book
    • Choice of talks
  • Cons:
    • Several inexperienced speakers

TXJS

    • Venue: Paramount Theater, Austin, TX
    • Format:
      • One day only
      • No keynotes
      • No choice of talks, topics grouped by general theme (25 minutes) – I thought this would feel restrictive, but due to the overall high quality of the presentations, it didn’t actually matter.
    • Pros:
      • High quality presenters
      • Great venue – This made a big difference to the overall feel, especially compared to the literal classrooms of Nodevember.
    • Cons:

 

  • Expensive – $200 for 1 day (no t-shirt, no lunch). This is where employer subsidizing is a huge benefit!

They were both fantastic experiences, but all things considered, I preferred TXJS. The venue was awesome, and the presenters were top notch, which in the end matters most.

 

Example Talks

This is a collection of some of my favorite conference talks:

Browsers vs. Native Apps (Andrew Dunkman)

Highlighted futuristic new browser features like ambient light sensing, webworkers, notifications, and geolocation.

Inline Styles (Jed Schmidt)

“There’s two things I don’t like about CSS – the cascading and the stylesheets.” Presented an entertaining, unique, contrarian viewpoint on the often-condemned practice of adding inline styles.

Progressive Enhancement (Jake Archibald)

Hilarious presenter, coined the term “lie-fi” to describe misleading Wifi signal on a phone, and showed the potential for much better offline experiences for websites and web apps.

 

Happy conferencing!

Originally posted on my personal blog.

The post You Should Attend A Tech Conference appeared first on The uShip Blog.

]]>
https://ushipblogsubd.wpengine.com/tips/you-should-attend-a-tech-conference/feed/ 0