Posted on Tuesday, October 30, 2007 at 5:05 AM
Concurrency is all about doing multiple things at the same time, and it probably matters now more than it ever has before. Consider a CPU running at 3 GHz, or 3x10^9 cycles per second. The speed of light in a vacuum is 3x10^8 meters/second, which matters for us because we cannot move information faster than this. Ah, and your CPU isn’t a vacuum so the speed that information moves around a CPU is slower than that. Even data did move at the speed of light, that still only allows for up to 10cm of data movement around a circuit per cycle.
This is not all that far, and you can see that scaling clock speeds up further and further will not be sustainable. Making the circuits smaller isn’t sustainable either – you must have sufficient space between “wires” in the chip or you get current leakage and capacitance effects (essentially, electrical problems). And let’s not even talk about quantum tunnelling (yes, we really are getting down to the sizes when quantum effects start to become a real issue)...
Posted on Thursday, October 25, 2007 at 3:46 AM
This article looks at one way that we have made Programmer's Heaven load faster, especially for our users outside of the US, using a service called CacheFly.
Understanding the problem
Web requests are made using the HTTP protocol. A web browser sends a HTTP request - a chunk of text specifying what file is required - over the network to the web server. The web server then gets this file and sends it over the network to the web browser.
There are two network related factors that affect the time that the request takes. One is latency: how long does it take for a bit of data to get from the browser to the server or vice versa. The other is the transfer rate: how many bits can we send or receive per unit time.
HTTP is layered on top of TCP/IP, the two protocols that together provide routing, error control and flow control. When you want to make a TCP/IP connection to a remote computer, you sent a packet to it. The remote computer responds with another packet stating that the connection is now open. This process is required to agree on sequence numbers. After that, packets of data can be sent - the data being the HTTP request. Finally, the web server sends something back...
Comments:
12
Tags:
HTTP,
cachefly,
tcpip
Posted on Saturday, October 20, 2007 at 2:32 PM
A little while back I answered a post on the PH forums about why you might need to use casts, and particularly why you might need to upcast. This article is a tidied up and extended version of my answer.
Variable vs. value types
Suppose we write a class B that inherits from class A. We can then say that B is a subclass of A. That means that you can use an object of type B anywhere that you can use an object of type A.
To understand upcasting and downcasting better, we need to introduce the idea of container or variable types and contrast them to value types. A variable may contain a value. For reference types, the variable has a type that states what type of value it can contain. However, the type of the value may be different; namely, it may be a subtype of the variable type. Let's clarify this with some examples.
A foo = new A(); // Variable type A, value type A
B bar = new B(); // Variable type B, value type B
A baz = new B(); // Variable type A, value type B...
Posted on Monday, October 15, 2007 at 1:53 AM
OK, OK, so I used to controversial title to lure you in. After all, it's hard to disagree that inheritance in object oriented programming leads to greater code re-use, and it's hard to disagree that code re-use is a good thing.
Before we dig in, let's have a quick recap on how inheritance gives us greater code re-use. You can write a class, then inherit from it to create a more specialized subclass. In that subclass, you may implement some methods that the parent class did not have. You may also specialize the behaviour of some of the parent's methods by overriding them. Any method from the parent class that you did not override, you inherit. You also inherit the state of the parent class (fields, attributes, or whatever you call them in your language of choice). Therefore, the same bit of code can operate on many different data types (since a subclass can be used anywhere that a class is). This is called polymorphism, and it is what enables safe code re-use (safe because you know that subclasses will have at least the state and operations of the parent class)...
Posted on Thursday, October 04, 2007 at 6:02 AM
Microsoft have
announced that the source code for many of the .Net Class Libraries is to be released to developers. This means that when debugging code that calls into the .Net class library, you will be able to trace into the library itself to see what is happening. Not all libraries will have their source released right away, though they plan to release the source for more of them over time.
This will potentially be very useful to those of us who want to know how things really work inside the .Net class library. A class library of this size is also going to have some bugs here and there, and being able to trace into it will provide a way for developers to know that the bug really is inside the class library rather than in their own code. That way, more detailed bug reports can be made to the Microsoft development team and a workaround may be easier to identify...
Posted on Tuesday, October 02, 2007 at 8:04 AM
One of the most frequently asked questions in ASP.NET is when to use HtmlEncode and when to use UrlEncode. Before digging into answering the question of what to use when, let's step back and look at what they are for.
Why encode data?
Web applications are mostly quite boring. Users enter stuff in a form, it gets stuck it in a database, and later on it is presented on a web page. All of these stages need some care from a security point of view, however. This article looks at the last stage.
Generating HTML is mundane, but there's plenty of room to get it wrong and introduce dangerous security problems. We often write things like this:
Username: <%=UserName%><br />
A user innocently entering a less than sign to make a creative username could, if it makes it into the generated HTML, make quite a mess of the layout of a page. For example, if the user enters:
I<3You
Then it is rendered as:
Username: I<3You<br />
...
Posted on Monday, October 01, 2007 at 7:57 AM
That's right, this is the very first post on the official Programmer's Heaven blog. Welcome! Here we will post about a whole range of topics. Coming up soon is a four part series on the new features of C# 3.0, including Linq, some practical advice about concurrency as well as a look into the future of it, advice on how to use encoding properly in ASP.Net to prevent cross site scripting attacks and more!
It's good to share, and we don't want to keep the ability to blog on Programmer's Heaven all to ourselves. Therefore, we will soon be enabling all Programmers’ Heaven users to create their own blogs on the site too! We are just about ready to launch this, and are ironing out the last few bugs. Your Programmer's Heaven blog will be free and we will feature the latest user blog posts in a box on the home page so you'll get read. And yes, we have implemented comments, RSS support, tagging and uploading of images to illustrate your posts. We look forward to reading what you blog about, be it how you solved a tricky programming problem or how you made a set of ice skates for your cat to use during winter. If you've done the second of these, we certainly expect pictures...