In future posts, we’ll address the following:
The answer there is “There are a lot of good reasons to do it, such as single‑page applications or validation, and much more that we’re going to talk about.”
The good news is it’s not nearly that bad. It’s actually pretty nice to work with once you know some of the key aspects of the language and how it works.
Obviously, it’s nice to give the Client that type of instant feedback. You’ll of course have to validate on the Server-Side, as well, but this will give the client an instant feedback scenario.
One of the big downfalls, I think, of the traditional Web applications is that every time you blink, it feels like, you’re doing a full‑page postback.
Today, we’re really moving a lot of data from the server‑side load down to the client side. I recently got a Galaxy Note 3 with a quad‑core processor right on my phone. Why not let the phone do more of the heavy lifting and go that route?
I’ll do a quick demo of a server‑side app versus a client‑side app. The first demonstration we’re going to look at is a pure ASP .NET app with C# on the back end. It has normal postbacks.
We’ll open it and you can see it’s very basic, just has a drop‑down.
As you switch the drop‑down, it’s going to load some customers.
We’ll go load all the customers in British Columbia. No big deal, right?
We’ll look at it using Chrome Developer Tools, you can hit F12 or do command or control‑shift‑I.
If We’re going to monitor the network requests. We can actually take a look at what is actually going back and forth over the wire.
We’ll select Alberta from the dropdown.
It looks like the size of that was 11.3K for this customer ASPX. Let’s go look at Arizona, there’s more in Arizona it’s 13K.
Let’s do one more. Montana is about 13K.
You can see the size of the page actually coming back is fairly consistent but it depends on your data.
This is using a little library called “KnockoutJS” to do data binding. It’s going to look the same, but let’s look at the actual data that’s sent back and forth.
Here’s the same type of app, but this is 100‑percent client‑side.
The server just serves up the initial HTML and then we make an API call, specifically Web API. This returns JSON data. It does the same thing, but let’s take a look at the size of the data that’s coming back now.
I’m going to click on XHR, which will mean our XML HTTP request, in other words, AJAX calls.
Let’s run British Columbia.
It looks like that was 1.8K of data. Not bad.
Let’s go to Montana again.
It looks like that was only 256 bytes. Not bad.
You can imagine if you’re designing your apps to run on a phone or a tablet or desktop, then this is a big deal.
Now, by leveraging AJAX, I’m able just to send the raw data that you can see here.
Both languages use functions. I think any language out there uses a lot of functions. That’s very common.
Finally, the conditional “if” statements, “switch” statements and “for loop” statements are practically identical in both languages. We’ll display those as well.
In this demo I have some C# code in a class called “Similarities.cs.”
I’ve broken down different parts of this. Variables.
We’re going to talk about some properties and some other features.
Let’s start with the one that’s open. In C#, we’re all used to doing something like prop tab tab to get a property definition. It looks like this.
You have a Get and a Set.
The current version, that this.age = 0 would be a very similar definition to a property.
It almost looks like a field it’s very similar.
You might wonder what the heck is this? It’s similar to C# however it changes context.
Basically, whoever calls into “this” is what “this” is. Whereas in C#, it always represents the actual object itself. A little bit different but very similar as far as what you can define.
Let’s go to a simple variable.
Here we have a C# method, called “GetName,” that returns a string.
You’ll notice it’s almost identical, aside from needing to input the “function” keyword.
Arrays – Loops – Conditionals
Finally, Arrays, Loops, and Conditionals are also very similar. Here, we have a little field names.
Pretty standard C# code, a bit contrived, but good for the demo.
We’re going to loop through. As we loop, if it equals zero (0), we’re going to add into the list up top, the list of string, first name. If it’s not zero (0), then, we’re going to add name, plus, whatever it is as we’re looping.
We use the function. Notice that the for loop is identical, because we can use var in C# if we want, for type inference. The if is identical. As we move down, everything looks pretty good.
You May Also Like
One of the coolest new features in Window Server 2012 and Windows Server 2012 R2 is the ability to clone a Domain Controller. In the past, if we had virtualized Domain Controllers and we actually took a snapshot of it and then rolled back to that snapshot, it would break the logon service on that … Continue reading How to clone a Windows Server 2012 or 2012 R2 Domain Controller
How does an investigator hunt down and identify unknown malware? In this recording of our IT Security training webinar on April 21, 2015, Security expert Mike Danseglio (CISSP / CEH) performed several malware investigations on infected computers and identify symptoms, find root cause, and follow the leads to determine what’s happening. He demonstrated his preferred … Continue reading Detailed Forensic Investigation of Malware Infections – April 21, 2015