It’s Sunday following my 7th week in Tech Elevator’s .NET Coding Bootcamp. This week we began studying the ASP.NET Model View Controller (MVC) Framework.
Model View Controller, or MVC, is a design format for modern websites. When we started learning about it, MVC made my head spin because it was difficult to understand how each piece interacted with one another. But once we dug deeper in class, it all made sense.
Before learning about MVC, it’s important to understand how modern websites work. If you’ve learned anything about web development, you know that pages are made with HTML and CSS. HTML holds the page’s content and CSS manipulates the HTML’s appearance with colors, layout, fonts, and so on.
At first, I thought every page on the internet had HTML specifically written for it. But if you think about it, creating that many web pages would be an insurmountable task for sites like Google or Amazon, who provide billions of combinations of data to your browser within seconds. With this in mind, it makes sense to have HTML pages serve as templates whose content can be populated from a database. That’s where MVC comes in; instead of having to write a specific HTML page for each of Amazon’s 500 million+ products, they create a single ‘product page’ in HTML, and use MVC to populate the product information from a database.
MVC applications consist of three types of classes; models, views, and controllers. From the user’s perspective, going to a web page happens in two steps; you click a link or enter a URL, and your browser presents the requested page. However, this actually happens in six steps, four of which run on a back end web application.
In short, here’s the entire process:
Your browser requests a web page and sends it to a back-end application. A controller class takes in the request and sends it to specific model classes, some of which can access database information. The model classes gather necessary data for your page and send it back to the controller. The controller sends the data from the model to a view class, which is a skeleton HTML page with programming language built into it. The view populates the HTML page with data from the model and sends it back to the controller. Finally, the controller sends the populated HTML page to your browser.
Here’s a sketch of the process:
This is a simplified version of a chart created by Tech Elevator instructor Josh Tucholski The model, view and controller pieces of an MVC program are simply sets of classes. The controllers coordinate the entire MVC process, the models store and fetch data, and the view is a hybrid HTML page with programming language built into it; for .NET developers, this hybrid language is called Razor.
Model view controller is by far the most advanced software development concept I’ve learned. But with the added complexity I’m capable of creating more dynamic websites, and doing it in much less time. I’m now learning some cutting-edge skills and I couldn’t be more excited about it!
I’ve come to realize how important it is to rely on code that’s already been written. If you’re new to development, a lot of code is provided in libraries. Libraries are classes that are already loaded into your integrated development environment (IDE), and offer solutions to common programming tasks. Using dates and times is a good example. The DateTime class is provided in C# with the Visual Studio IDE, and it allows us to process dates and times without having to write a lot code.
A few weeks back, I was struggling with the idea of using libraries. I felt like I wasn’t writing complex code, and was taking advantage of other people’s work. One day, I was walking with one of the Tech Elevator instructors, Joe, and I brought this up. He empathized with me and jokingly said “we stand on the shoulders of giants,” and we went about our day. I thought of this as an excuse to be lazy at first. But thinking more deeply, “standing on the shoulders of giants” is exactly what we’re doing. The code inside programming libraries was once written to help modern developers do more. Maybe my code doesn’t establish what a date and time is, but I can develop far more advanced programs using dates because somebody already did the leg work. I’ve come to see libraries for what they really are; a collaborative effort to accelerate innovation. Libraries allow us to focus on modern problems without sweating the issues that have already been resolved.
The idea of “Standing on the shoulders of giants” is salient because the ASP.NET MVC Framework relies heavily on libraries and convention. It’s more dependent on built-in rules than actual programming logic. My instructor, John, continually asks us to “use convention over configuration.” This means we should follow what the framework says to do, not necessarily what we think is logical. Jumping into ASP.NET MVC is a little concerning because I’m a strong supporter of open source software, and this framework is proprietary software owned by Microsoft. However, in exchange for being indoctrinated into Microsoft’s framework, I’m learning some valuable skills. Also, the essential concepts of MVC remain the same. With all of this in mind, I’m happy to be learning Microsoft’s version of MVC, and if I have the opportunity, I’ll explore an open source version in the future.
That’s it for this week! Thanks for reading! If you want to get in touch, reach me at joeosterfeld@gmail.com