Ayende @ Rahien

It's a girl

What a Great .NET Developers Ought To Know: Answers

 Scot Hanselman has a list of question that you would interview a .Net candidate with. Here are my answers (without using MSDN/Google/Help/etc, just my head):

There are 102 questions, I couldn't answer 20 of them (19.6%), (you judge if I was correct or not).

I'm weak in ASP.Net & Xml, but that is no surprise to me.

Everyone who writes code

  • Describe the difference between a Thread and a Process?
    • A thread is a path of execution that run on CPU, a proccess is a collection of threads that share the same virtual memory. A process have at least one thread of execution, and a thread always run in a process context.
  • What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
    • Windows service doesn't require a logged on user to activate it, (there is a bit more, but that is basicaly it).
  • What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
    • Hm, that is a tough question, there is the 2Gb of normal user space, 3Gb if you run windows with the right switch (which has problems of its own, apperantly) and the max virutal memory of 32bits machine is 4Gb. This affect system design when you reach big things such as databases, applications server and Enterprise "stuff" that require a lot of memory.
  • What is the difference between an EXE and a DLL?
    • An exe is an EXEutable file that contain instructions for the processor to run as well as an entry point to start execution (main() in C/C++, Public Static Void Main() in .Net). A dll is a file that contain a piece of functionality that an exe will call.
  • What is strong-typing versus weak-typing? Which is preferred? Why?
    • Strong type is checking the types of variables as soon as possible, usually at compile time. While weak typing is delaying checking the types of the system as late as possible, usually to run-time. Which is preferred depends on what you want. For scripts & quick stuff you'll usually want weak typing, because you want to write as much less (is this a correct way to use Ensligh?) code as possible. In big programs, strong typing can reduce errors at compile time. Going any further will cause Holy War, so I stop here.
  • Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.
    • No idea what a componenet container is, sorry.
  • What is a PID? How is it useful when troubleshooting a system?
    • Process Identifier, usually so you can kill an offending process (at least that is how I use it) or for logging / debugging purposes.
  • How many processes can listen on a single TCP/IP port?
    • AFAIK, One. It make sense, but I'm not 100% sure. The results of more than one process listenning to the same port would be strange at best.
  • What is the GAC? What problem does it solve?
    • Global Assembly Cache. Versioning. Dll Hell, etc.

Mid-Level .NET Developer

  • Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
    • That one is tough, Interface oriented would probably be (first time I hear this term) writing everything in terms of interfaces and only using the interfaces, using concentrate classes for instatition only. Object orient is the shebang of classes, polymorphism, inheritance, and the like. Very powerful, allows you to hook your objects together and just let the program run. OO is a must for Interface bases. Aspect Oriented programming is when you have code running on certain aspects of your code (method entry, method return, exception thrown, etc) most useful in logging and security.
  • Describe what an Interface is and how it’s different from a Class.
    • Interface define a contract, but no executable code. Interface is implemented by classes.
  • What is Reflection?
    • A way to explore the structure of assemblies at run-time (discover which classes/resources/methods there are).
  • What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?
    • Never done either, but XML WS is interoperatable, and .Net Remoting is extensible.
  • Are the type system represented by XmlSchema and the CLS isomorphic?
    • No.
  • Conceptually, what is the difference between early-binding and late-binding?
    • Early binding is knowing at compile time what you are calling, late binding is discovering it in run time. That is not a good explanation, but generally this mean whatever you're using a concentrate class or an interface.
  • Is using Assembly.Load a static reference or dynamic reference?
    • Dynamic reference.
  • When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?
    • When trying to load a file that is not on your private path. (Plug-ins comes to mind, or things like Reflector).
  • What is an Asssembly Qualified Name? Is it a filename? How is it different?
    • It contain the name of the assembly, its version and its public key, it's not a file name, and it's different in that it allows signing and versioning.
  • Is this valid? Assembly.Load("foo.dll");
    • No, Assembly.Load() accept assemblies names and not file names (got bitten by that a few times).
  • How is a strongly-named assembly different from one that isn’t strongly-named?
    • It's an assembly that has been signed using public/private key pair. It can be placed in the GAC, mainly. It also help is versioning and code verification (if you know the publisher Public Key, you can verify that it hasn't been tampered with.)
  • Can DateTimes be null?
    • No, and it sucks that they can't.
  • What is the JIT? What is NGEN? What are limitations and benefits of each?
    • Just In Time compilation, it allows for better compilation magic because the JIT knows a lot more about the code when it's running, long startup time. NGen is compiling ahead of time, faster startup time, but not as much info for the compiler, so it may not produce as efficent code.
  • How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?
    • It divide them to three generations, the first one is short lived and is collected often (and is cheap to collect), the other two are for longer term objects. Non deterministic finalization means that your object's finalizer (destructor in C++) isn't called when it falls out of scope, its memory isn't even neccecarily released when it falls out of scope .OTOH, it may be collected when it's still in scope, if you're not using it anymore.
  • What is the difference between Finalize() and Dispose()?
    • Dispose is called by the user (hopefully via using()) and Finalize is called by the runtime.
  • How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
    • Make it harder to forget to release resources, IDisposable is an interface that define a way to release resources in a predicted way. It means that when you're out of the using() statement, then the object's Dispose() has been called and its resources (but not memory, that is up for the GC) are free.
  • What does this useful command line do? tasklist /m "mscor*"
    • Hm... No idea. First time I see the tasklist command. Maybe list only the processes that link to mscor* ? Probably will show all the processes that uses .Net.
  • What is the difference between in-proc and out-of-proc?
    • in proc is faster, out proc require marshaling between the process. There are more, but that is the main thing.
  • What technology enables out-of-proc communication in .NET?
    • Hm, Remoting for one, Windows Messages is another, all of Win32 RPC is yet another. Named piped, memory mapped files, etc.
  • When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?
    • I don't know this one, but I think it's aspnet_wp.exe in XP & 2003 (never worked with that one, sadly) and inetinfo.exe for 200.

Senior Developers/Architects

  • What’s wrong with a line like this? DateTime.Parse(myString);
    • No locale? No variable to store the returned date? Not using ParseExact? No try-catch? Hard to tell.
  • What are PDBs? Where must they be located for debugging to work?
    • No idea what the TLA is, but they are debug symbol that tells the debugger which instruction belong to which line of code.
  • What is cyclomatic complexity and why is it important?
    • Even my dictionary doesn't know what "cyclomatic" is, but I would hazzard a guess and it's probably some sort of measuring method for the complexity of software.
  • Write a standard lock() plus “double check” to create a critical section around a variable access.
    • I know this one, but I can't recall how to do this, I'll finish the rest of the questions and return to it. Okay, I returned and here is my implementation.
      if(shouldLock)
      {
       lock(lockableObj)
       {
        if(shouldLock)
        {
         DoWork();
        }
       }
      }
  • What is FullTrust? Do GAC’ed assemblies have FullTrust?
    • Your code is allowed to do anything in the framework, meaning that all (.Net) permissions are granted. The GAC has FullTrust because it's on the local HD, and that has FullTrust by default, you can change that using caspol (I always think of that as cesspool for some reason.)
  • What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
    • Early failure if you don't get it. Easily discover what are the permission that the code need, etc.
  • What does this do? gacutil /l | find /i "Corillian"
    • Didn't get to work with gacutil, but /l is probably list, so this print all the assemblies in the GAC that has Corillian (not case sensitive).
  • What does this do? sn -t foo.dll
    • Does something to the strong name of the dll, probably show you the details of it, don't recall sn's CUI in my head.
  • What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
    • Port 135 is for windows RPC, a much abused service. Can't recall what ports are for DCOM, but that is easily discoverable.
  • Contrast OOP and SOA. What are tenets of each?
    • OOP - Objects is everything (inheritance, ploymorphism, interfaces, etc). SOA - Services are the main thing (discoverability, interoperability, versioning, etc. At least those are the buzzwords that I hear, don't have experiance with this).
  • How does the XmlSerializer work? What ACL permissions does a process using it require?
    • It reflect on your object and read the attributes and then output the values according to it. I'm not aware of ACL permissions you need for this (ACL being Windows), but you need ReflectionPermission in order to use it (a .Net permission).
  • Why is catch(Exception) almost always a bad idea?
    • This means that you swallow an exception and not do anything about it. There are very few cases when it's okay to do that, usually when you have an action you don't care if it failed or not, or maybe you just care that it failed, and not why (validating input integer is one such case:
      try 

       i = int.Parse(str); 
       Console.WriteLine(i+ " is a number");
      }
      catch (Exception) 

       Console.WriteLine("This is not a number"); 
  • What is the difference between Debug.Write and Trace.Write? When should each be used?
    • The Debug.Write call won't be compiled when the DEBUG symbol is not defined (when doing a release build). Trace.Write calls will be compiled. Debug.Write is for information you want only in debug builds, Trace.Write is for when you want it in release build as well. And in any case, you should use something like log4net because that is both faster and better :-)
  • What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
    • Debug build contain debug symbols and can be debugged while release build doesn't contain debug symbols, doesn't have [Contional("DEBUG")] methods calls compiled, can't be debugged (easily, that is), less checking, etc. There should be a speed difference, because of disabling debug methods, reducing code size etc but that is not a gurantee (at least not a signifcant one)
  • Does JITting occur per-assembly or per-method? How does this affect the working set?
    • I believe that per method, but not certain. The working set should be smaller becaue methods that weren't called weren't JITed (meaning less memory taken, etc).
  • Contrast the use of an abstract base class against an interface?
    • Abstract base class can contain code, but there are some methods that are marked abstracted (no code) that an inheriting class must implement. This is a useful way to have some default action if the inheriting class isn't interested in override some method. Interface has no code, and an implementing class must implement all methods.
  • What is the difference between a.Equals(b) and a == b?
    • The first checks whatever the objects are equal, the second whatever they are reference-equal (the same object). At least that is the way it work in Java, didn't have trouble using just == everywhere in .Net, so far.
  • In the context of a comparison, what is object identity versus object equivalence?
    • Hm, that is a tough one. Object identity can mean either the same object (you've two references for the same object) or (not very often unless you are in ORM world) database identity. Basically, object identity mean that they are the same object (same place in memory or same row in the DB) and object equivalence means that they are a diferent objects but has the same value (all fields are are Equal() ).
  • How would one do a deep copy in .NET?
    • Implement IClonable? That is the way I would do it.
  • Explain current thinking around IClonable.
    • Uh... no comment is not a good answer?
  • What is boxing?
    • Taking a value type (on the stack) and putting it on the heap.
  • Is string a value type or a reference type?
    • reference type with immutable semantics (proof, you can do this: string s = null;).
  • What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?
    • No idea.
  • Why are out parameters a bad idea in .NET? Are they?
    • .Net doesn't verify that an out parameter is set inside a method that uses an out parameter before an exception is called. This mean that you may use an uninitialized parameter without the compiler catching on to this. Use ref parameters instead. Personally, I think that it's a problem.
  • Can attributes be placed on specific parameters to a method? Why is this useful?
    • Yes. I think that for Remoting scenarios, but I'm not sure. I know that I saw such things, but never really paid much attention to it.
  • C# Component (HI, TP) Developers
    • Ha? Is this a question?
  • Juxtapose the use of override with new. What is shadowing?
    • Override means that using your class throught a base class will use your method, while new means your method will only be called if accessing through your class, and when using your class throught a base class the base class method will be called. I think that shadowing is the using new, but I'm not certain.
  • Explain the use of virtual, sealed, override, and abstract.
    • Virtual - a method that can be overriden in an inheriting class, and the invoked method will be the derived class one.
      Sealed - means that you can't inherit from a class, often annoying when it's on the BCL.
      Override - a marker that verify that you indeed override a method and no just create a method with the same name & parameters by mistake
      Abstract - a method that are not implemented, abstract methods are virtual, and abstract classes are explained above.
  • Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
    • Foo.Bar - (so you won't get Foo.Baz by mistake), Version=2.0.205.0 - The version of the assembly, that you won't get the version 2.0.0.0 (dll hell), Culute=neutral - in case you are into globalization :-), PublicKeyToekn=... - verify that this file is indeed the file you are thinking about and has not been tampered with except by the original publisher.
  • Explain the differences between public, protected, private and internal.
    • Public - anyone can use, protected - only inheriting classes can use, private - only this class can use, internal - only members in this assembly can use.
  • What benefit do you get from using a Primary Interop Assembly (PIA)?
    • IIRC, using a COM compnent?
  • By what mechanism does NUnit know what methods to test?
    • Refection & Attributes.
  • What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
    • The last one preserve the exception stack, it really should've been rethrow;
  • What is the difference between typeof(foo) and myFoo.GetType()?
    • typeof(foo) is a compile time structute, and foo is a type name, myFoo is an object, and GetType() is a method that return in run-time.
  • Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
    • The c(string) calls to c(), this is useful if you've a basic constructor that initialize all the fields, and then you can avoid duplication of code.
  • What is this? Can this be used within a static method?
    • a reference to the current object, static methods don't have an object, so they can't use this.

ASP.NET (UI) Developers

{Note, I'm not much of ASP.NET UI developer, but I'll try it anyway}

  • Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick.
    • Probably something in the Application that takes the POST and fire an event, the spesifics I never had to find out. 
  • What is a PostBack?
    • A way for the page to notify the asp.net application that some even occured (button clicked, etc).
  • What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
    • A way to preserve the state of controls when doing postbacks, I think it's Base64 encoded, I don't think it's encrypted by default, though it probably can be. Nearly all web controls use it.
  • What is the <machinekey> element and what two ASP.NET technologies is it used for?
    • A public key that used for session & caching services when they are done in a cluster and no just a single server.
  • What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each?
    • in proc - fast, if the process crash then you lose state. out proc - slower, if the process crash you preserve state. Sql Server - slowest (network), you preserve state and can use the state from multiply machines.
  • What is Web Gardening? How would using it affect a design?
    • Clusters? No idea, as a matter of fact.
  • Given one ASP.NET application, how many application objects does it have on a single proc box? A dual? A dual with Web Gardening enabled? How would this affect a design?
    • Hm, no idea again.
  • Are threads reused in ASP.NET between reqeusts? Does every HttpRequest get its own thread? Should you use Thread Local storage with ASP.NET?
    • Yes, threads are reused, Request can jump between threads, and TLS wil not work, use the request context.
  • Is the [ThreadStatic] attribute useful in ASP.NET? Are there side effects? Good or bad?
    • Not really, because request may be served from multiply threads, you may get a different object from another request. Very bad.
  • Give an example of how using an HttpHandler could simplify an existing design that serves Check Images from an .aspx page.
    • No idea what the question is, what is "Check Images" ? Maybe URL Rewriting (my one use for HttpHandlers)
  • What kinds of events can an HttpModule subscribe to? What influence can they have on an implementation? What can be done without recompiling the ASP.NET Application?
    • No idea.
  • Describe ways to present an arbitrary endpoint (URL) and route requests to that endpoint to ASP.NET.
    • No idea, probably URL Rewriting and IIS redirection/virtual directories?
  • Explain how cookies work. Give an example of Cookie abuse.
    • The server tell the browser to put this file in a cookie, and the client then send all the cookies for the domain in each request. Possible abuses are big cookies which affect network traffic and speed of surfing and privacy (1x1 gifs).
  • Explain the importance of HttpRequest.ValidateInput()?
    • I'll have to learn what this is first, sorry.
  • What kind of data is passed via HTTP Headers?
    • document name, size, culture, mime type, basically the document meta data.
  • Juxtapose the HTTP verbs GET and POST. What is HEAD?
    • GET tells the server to send it a spesific page, POST also send variables (in GET they may be trasfered using query string) with the request, HEAD tell the server to send just the headers, and not the actual content.
  • Name and describe at least a half dozen HTTP Status Codes and what they express to the requesting client.
    • 200 - Ok, 404 - Document Not Found, 304 - No Update Neccecary, 500 - Server Error, 401 - Autorization Error
  • How does if-not-modified-since work? How can it be programmatically implemented with ASP.NET?
    Explain <@OutputCache%> and the usage of VaryByParam, VaryByHeader.
    • if-not-modified-since header allows the server to send 304 reponse (not modified) and not the full content of the page. You implement this by capturing the headers, checking for the presence of if-not-modified-since value, and then returning 304 status code. I believe that this is the hard way and OutputCache will do it for you if the client send if-not-modified-since. VaryByParam means that the cache hold different copies of the page for different parameters, and the same is true for different header for VaryByHeader
  • How does VaryByCustom work?
    • Probably by implementing some interface or abstract class, but I don't really know.
  • How would one implement ASP.NET HTML output caching, caching outgoing versions of pages generated via all values of q= except where q=5 (as in http://localhost/page.aspx?q=5)?
    • Use VaryByCustom, I would guess, but I don't count this as an answer as I don't know what VaryByCustom really does.

Developers using XML

(I don't like the angle bracket tax, and it shows)

  • What is the purpose of XML Namespaces?
    • To allows me and you to use the <Id> tag without grief and pain.
  • When is the DOM appropriate for use? When is it not? Are there size limitations?
    • Small documents, and you need to modify the content. Big documents need to be loaded to memory entirely, so it's wasteful. Size limitation - probably so, but the performance is more often a consideration
  • What is the WS-I Basic Profile and why is it important?
    • I'll need to get back to you with that one :-)
  • Write a small XML document that uses a default namespace and a qualified (prefixed) namespace. Include elements from both namespace.
    • I know this, but I can't recall the syntax from the top of my head, (xml:ns?).
  • What is the one fundamental difference between Elements and Attributes?
    • Element can contain another elements and attributes?
  • What is the difference between Well-Formed XML and Valid XML?
    • Valid Xml is validated against a schema/dtd/etc, Well Formed Xml obey only to the grammer of XML, and valid XML is also well formed, but the reversed is not true.
  • How would you validate XML using .NET?
    • XmlValidatingReader, most probably.
  • Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes("//mynode");
    • The mean search me and all my childrens, this can cause to bad performace as unneccecary searches are made. It's much more efficent to use the full or relative path. I can't think of a good use right now, maybe when you really do want all the mynode nodes? (For counting them, or doing some work on them, etc).
  • Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
    • In XmlReader you control the parsing, you move from one place to another using methods, Sax parse the Xml in its own time, and raise events whenever it find something interesting. Personally I like XmlReader, but I've never used Sax, so I can't tell much more.
  • What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
    • XPathDocument is not editable, that is the first and most important thing. Otherwise, it allows fast XPath queries. When I want to pull data, I'll use XPathDocument, when I need to edit it, I'll use XmlDocument.
  • What is the difference between an XML "Fragment" and an XML "Document."
    • I think that Xml fragement obey all the rules of Xml, but it doesn't have <?xml?>. No certain about this one, though.
  • What does it meant to say “the canonical” form of XML?
    • Without whitespace etc, just the content, regardless of the way it was saved.
  • Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
    • No idea.
  • Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
    • DTD & XSD are both ways to spesify a format for an XML dialect. XSD is written using XML, and DTD looks like a big regex. I rather read XSD, because I don't need to make the mental shift from XML to DTD dialect.
  • Does System.Xml support DTDs? How?
    • I think that it must to offfer a complete support, but I don't know.
  • Can any XML Schema be represented as an object graph? Vice versa?
    • I belive so, but not certain. Vice versa - I don't think so.

Comments

No comments posted yet.

Comments have been closed on this topic.