Note: Originally posted on August 26, 2016 at Geekswithblogs.net .
I had the privilege of spending time with four interns at Omnitech this summer. See our @Omnitech Twitter feed or our site to learn more about Omnitech. Sometimes it’s difficult to know how to have interns at a company, but we see it as an investment in them, the community and ourselves. We’ve had several interns in the past become valuable employees. It’s fun to see how much they grow personally and technically in just a few months or years.
I didn’t have the opportunity to work with them directly, but I was talking to a few of them as they were getting started. They were working on a web page for a real project that needed to filter data and show it in a grid. With my background and experience in web development over the last 9 years, I said something like “did you know that there is more to web development than jQuery? Grab me next week (I’m only in the home office 2 days a weeks) and I’ll show you a few things.” I was almost surprised when I got an email a day later asking if I could join them for their weekly lunch. Good for them for taking initiative!
I put together something short to talk about and get us on the same starting point and then we dove into some of the code they had written early that week.
I first ran through a quick history tour of the web as I “bingoogled” it and saw it (I took about 5 minutes to put this together :-)).
Update: In December 2017, Richard Campbell on DotNetRocks for their 1500 show gave a history of .Net with a promised book to come. It’s worth listening to.
Update: Brendan Eich (JavaScript and Brave) gave a talk posted on Aug 6, 2018 A Brief History of JavaScript
Understanding Server vs Client
Doing more in JavaScript means doing more work on the client. It also means sending more bytes and changes the paradigm from the Asp.Net MVC/Web forms with postbacks. We need to use the right tool for the job and understand the tradeoffs.
Server: MVC, @Razor, Web Apis (serves up the files (html, css, js) and data (Json/xml)
Client: Browser is like a mini-OS. Runs the javascript and executes it.
I see a logical progression from the “old” way of augmenting server rendered pages to the “modern” way of doing more work on the client with JavaScript.
There’s always more to learn: Checkout Simona’s diagram Tweet
We started from something like this snippet of code in a Tracking.js files. I’ve left out some details on the FilterOnChange and other parts. This was getting pretty complex and hard to follow. Notice the usage of $(document).ready and lack of logical methods (I often see this when developers are using jQuery to do more complicated UIs). We can use good coding practices with JavaScript, just like we’ve learned in C# and other languages. They were reading Clean Code by Robert Martin in a book club at the time, so I enjoyed seeing how they started connected the dots to JavaScript over the next few weeks.
$(document).ready(function () {
$('.mrDrop').change(function () {
FilterOnChange().done(function(data){
$('.subDrop')
.find('option')
.remove()
.end();
$.each(data.SubMarketers, function (key, value) {
$(".subDrop").append('<option value="' \+ value.Item1 + '">' \+ value.Item1 + " \- " \+ value.Item2 + '</option>');
});
$('select.subDrop')\[0\].sumo.reload();
$('.subDrop').trigger("change");
});
});
$('.subDrop').change(function () {
FilerOnChange();
});
$('.siteDrop').change(function () {
FilterOnChange();
});
$('input\[name="Enabled"\]').change(function () {
FilterOnChange();
});
$('.toggle').click(function () {
TrackingPageHandler.FilterOnChange().done(function () {
$('input\[name="Enabled"\]:Checked').trigger("change");
});
});
});
After a half hour we were on our way to an object orientated approach with a better separation of concerns.
In the .cshtml file.
<script>
$(document).ready(function(){
var tracker = new Tracker();
tracker.initialize();
// etc
});
</script>
In our Tracker.js we started moving towards something like this.
// we struggle a little to get the class approach correct. I’ve been in TypeScript ( www.typescriptlang.com ) for too long :-). http://www.objectplayground.com was helpful.
// Constructor
function Tracker() {
}
Tracker.prototype.FilterOnChange = function FilterOnChange() {};
Tracker.prototype.GetData= function GetData() {};
// more methods, etc
There’s a lot of things we can learn about in the web development world. We all agreed to continue meeting weekly, to see how I can help them shorten the learning time. We continued with meetings with introductions to MVVM, data-binding with KnockoutJs , RequireJs, TypeScript, unit testing with Jasmine and in C#, and builds with TFS. It was fun to see the improvements in in how readable the code was, their understanding of topics and growth over the summer. I felt that we gained the most value from our time when we spent time with code they were working with, instead of demo code.
Some of this turned into my series and talk From JavaScript Mess to Cleaner Code .
Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)
Also check out my Resources Page for referrals that would help me.