Free eBook: Foundations of Better Programming


Karl Seguin recently released a great free 79 page eBook for .NET developers covering design patterns, unit testing, mock objects, memory management, object relational mapping, and more.  Get it while it's free!

The Discussion

  • littleguru
    Cool book. Thanks for sharing, Dan.
  • Jason Teale

    I'm only into the second chapter, and I just had to say - fantastic book!
    Most of the books out there tend to be just API references, but to have this kind of stuff down on "paper" in a coherent manner is extremely useful.

    Have you ever thought about writing a full length, in depth book?

  • Dan
    Hey Jason,

    I agree with you that many are just rehashes of the API with simple, almost unusable samples with each. One of the things I liked about Karl's book is that he teaches you not just how to build software but how to build better software.

    As for me writing a book, I'm knee deep in co-authoring a Coding4Fun book actually Smiley  The book's content is centered around buildnig 10 fun, cool projects on everything from YouTube, World of Warcraft, the Wiimote and more.

    As for a more in-depth book, it depends on what you mean. A lot of the larger books (1,200 ASP.NET page books) only cover each topic in 15 pages, but they cover a LOT of topics, just not deeply. Then there are single books that go very deep, and those are good if you want to know what the heck is actually happening like Jeffrey Richter's CLR via C#. I'm probably best suited for an applied book with actual projects as documenting APIs to me isn't personaly interesting, but showing how and when to use those APIs in an application is. As for a Richter-type book, I'm not the right person and I don't think I could compete with him anyways Smiley

    There are a couple of other books that I think the .NET community needs though -

    Pragmatic Business Intelligence for Developers - SQL Server 2008 BI using real-world examples like US Census data, Technorati search data, YouTube video popularity, etc.

    Simple, Beautiful WPF Designs for Developers - This was a personal pain for me having read multiple WPF books and flipped through several including Expression Blend books - almost none of them show you how to make something attractive. Go to a bookstore and flip through WPF/Blend books and you'll see terrible-looking UIs with big green and red blocks. This book would be a collection of WPF control skins, quick usability guidelines, and instructions for how to reuse and structure them in your applications.

  • littleguru
    You are writing a book? When does it come to the shelves?
  • Dan

    By December, it's due out by the first week of August (gasp!) Here's the book on Amazon, note that the title isn't final Smiley

  • Bas
    Great, this and the Silverlight 2 book ended up straight on my mesh. Can't wait to browse through them at home.

    One of the things I liked about Karl's book is that he teaches you not just how to build software but how to build better software.

    True. Coding stuff that works is only part of the goal; coding it well is another matter entirely. It's the main reason why Steve McConnell's Code Complete (2nd edition) is downright the best programming book of all time. I use stuff I learned from that book every single day.
  • elemental
    Just wanted to say thanks for the kind comments about the book. Hope it's useful Smiley

  • wkempf
    IF you ignore the snarky comments about Microsoft, it's a very good book.  But then, that's like most of the posts from the ALT.NET folks.  IF you ignore the snarky comments about Microsoft, they have a lot of things to bring to the table.
  • elemental
    I think the snarkyness is pretty much gone by chapter 2, which isn't surprising since chapter 1 specifically deals with ALT.NET Smiley
  • gogole
    Good book from what i've read so far, really learning alot . I hope this is one out  of many to come. Kudos to Karl Sequin Smiley. It really is true : the best things in life are free Big Smile.
  • Dan
    Hey Karl, it's definitely a great resource for the .NET developer community and I think it's great that it's also a sort of work in progress in that readers are providing feedback on content and that you're evolving/updating it based on that feedback.

    Keep up the good work!
  • mattv
    Really, really great book.

    I am however a bit sceptical about whether O/R mappers, or NHibernate in particular is suited for most projects.
    They can lead to much less development time, yes, but as far as I've understood from different blog and forum posts, they can cause all kinds of other headaches, when you try to do something a bit complex.
    The last thing i would want to be forced into, is designing my system around an O/R.

    I do feel that writing my DAL manually, is a time consuming process. It does however give me an extra sense of control, and a few abilities that wouldn't be possible using an O/R.
    Karl mentions in his book that what you really need to do, is take a leap of faith, but with the O/Rs available today, it seems impossible to me that you can avoid designing your system around the shortcomings of the O/R.

    I haven't tried building a system on an O/R mapper yet, since I just don't trust it. But if you have different experiences, please tell me that I have the wrong idea. I'm particularly interested in whether it holds up in an enterprise service environment.
  • elemental
    I was just looking at some older code we wrote and thought it might alleviate [some of] your concern. Essentially:

    public abstract class NHibernateDataStore : IDataStore
        public User GetUserByCredentials(string userName, string password)
              _session.CreateQuery(from User where UserName ....).UniqueResult<User>();
        public abstract ProductResult SearchProducts(...);
    public class MySqlDataStore : NHibernateDataStore
         public ProductResult SearchProducts(...)
              //hand coded sql, sproc, whatever

    95% of the logic is within the NhibernateDataStore, but some queries needed special optimizations (after profiling) or were just too complex, so were hand-coded the SQL within the MySqlDataStore.

    This seems like a win-win, you get the quicker development time, with no constraint on flexibility. NHibernate will only box you in if you let it - but it's pretty easy not to get yourself in that situation (and pretty easy to get out of it anyways).

    Would that address part of your concern or is there something more to it? I certainly don't advocate NHibernate in every situation, but I do believe that people who aren't familiar with it will probably never end up using it even when it's the perfect fit.
  • mattv
    Hi Karl,

    I see what you're getting at. And I realize how that could be utilized.

    Some of the functionality that I'm quite sure I would need at some point, and not really sure whether is supported by NHibernate, is something like this:

    For the sake of argument, let's take a User object that needs to be persisted with NHibernate, this User has a property called Name which is of the type Name that is a combination of Firstname and Lastname. Here's some code for clarification:

    public class Name
            public string Firstname { get; set; }
            public string Lastname { get; set; }

        public class User
            public Name Name { get; set; }

    How would i go about mapping Name.Firstname and Name.Lastname into my Users table Firstname and Lastname column? Is it even possible?

    And how about reading it back from the database? What if my Name type can only be initialized with a constructor that has both firstname and lastname as parameters?
  • elemental
    MattV: this is a pretty simple scenario for NHibernate. To answer your second question, when you create a mapping in NHibernate, you can tell it which access and naming strategy to use. So you could tell it to access FirstName and LastName via a field using the "camelcase-underscore" strategy. NHibernate does require a default constructor (no parameters) to be present, but it doesn't have to be public. I consider this acceptable since it doesn't require a change to your API (I think RhinoMocks requires a default constructor on Partials anyways, and if not that, something else, so it tends to be requirement for most framewoks).

    As for the first question, NHibernate handles this via composition, and the Name example is actually the one they give in their documentation (http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#components-dependentobjects).

    I think I've had trouble mapping on one or two occasions. Typically, the cause of that has been my own ignorance about NHibernate, or a design decision that ended up not being the best. If you use it enough, and depending on what you do, I do think you'll run into situations that no longer map nicely. I guess in those situations, you hand roll your own mapping, or move to an even more flexible O/R mapper (never used it, but i think iBATIS is what people who recommend in those situations).

  • mattv
    Aha, I see... that's actually pretty neat.

    Perhaps I should be a bit more optimistic, and read through the documentation to get a proper picture of what can be done.

    One last question. I have multiple times tried to get used to writing unit tests, but usually sorta give up, because I feel lost when it comes to what should be tested, and how deep my tests should go.
    Can you from the top of your head mention a book or other writing that you felt was useful when you were learning?

    Thanks for the pointers so far.
  • elemental
    Humm...I do agree that is the hardest part about learning to unit test. When you first start up you end up with a lot of little test that seem to add no value, and some really big ones that seem overly complicated.  I did write a few blog posts about my adventures in TDD that I think might be useful: http://codebetter.com/blogs/karlseguin/archive/tags/TDD/default.aspx but aside from that I neither have a really good book or any type of resources.

    I know that there's some backlash starting to grow about interaction testing, but I still think the best think to do is learn a good mocking framework (RhinoMocks) and start with some interaction testing. This will first and foremost immediatly highlight tight coupling in your code, which you then must fix using some type of IoC (StructureMap's Dependency Injection comes to mind) and with that done you start to see far more meaningful tests.  The Ebook covers it all, although it's high level and the end to end code examples are a little few and far inbetween.
  • mattv
    I guess it's just a matter of diving into it and sticking with it until it's second nature.

    Regarding the test tool, is there anything wrong in using the unit test tool built into VS2008 instead of NUnit?
  • elemental
    Never used it, so can't say for sure, but I'd bet you're pretty safe. Testing frameworks are pretty straightforward in my experience.
  • johanlindfo​rs
    Karl: This resource is truly valueable for all .NET developers, but I am a bit surprised by the fact that the "Foundations of Programming" doesn't include anything regarding security. How come? In my opinion if we could have a community focusing on recommendations and guidance on security, as vocal as the community focusing on persistence, we would have a much better story all together as developers.


    Johan Lindfors
    Microsoft Sweden
  • elemental
    Thanks for the feedback. Honestly, I never even thought about it (which I realize highlights the problem you'd like to see addressed). I'm not even sure I'd know what to talk about.

    Would you say that people who do server-centric programming (be that websites or web services) generally worry less than people doing desktop development? I mean, assuming the server is hardened, I don't have to worry about someone modifying my libraries, invoking private members, or manipulating system memory. The security I do worry about tends to be application specific - roles, permissions and input validation. Even the security protocol is pretty high level - SSL or some type of asymmetric key exchange.

    I guess what I'm saying is that even though I'm more than willing to wing my "expertise" on some topics, security isn't one of them.

    If you have any resources for me, I'd be more than happy to learn.
  • gogole
    Unit testing is foreign to me but i'm ready to learn it.I would like to try out the in-built testing system in VS2008. Any references to relvant information and tutorials  from you guys on this would do me alot of good. thanks Smiley
  • Keith J. Farmer
    My impression is that it's a well-meaning draft.  Overall, however, I was dissatisfied with it.

    Primarily, my concern is that there are such obvious inconsistencies -- such as a comment about pointers being unavailable in C#, soon followed by an example of using them in C# -- and glaring omissions.

    In particular, while the text mentions .NET 3.5 in the present tense, I failed to see any discussion about LINQ as a pattern for data access.  Indeed, the only discussion of .NET's data stack appears limited to .NET 2 -- the DataSet stack.  I'm fine if you want to be a cheerleader for NHibernate (I have no desire to use it, personally), but even NH is building a LINQ layer.  It comes off as either careless (you overlooked, somehow, the single biggest feature of .NET 3.5, and pretty much the only feature which could have stopped Orcas from shipping), or disingenuous (you intentionally failed to discuss it).  I refuse to believe the latter possibility, but the former is pretty bad in itself.

    My suggestion would be to have a couple hard-core technical reviewers, both ALT.NET and MS if that's your preference, who can guide you to make sure your discussion is sound and complete.  You have the core of a good, informal guide (my manager is having our new grad hire lead a discussion of it) but I wouldn't call it ready in the context of what it's purporting to discuss.

    (I admit, I'm not volunteering -- I've already done my technical review for a book.  I'm making up for lost sleep now.. but seriously, good luck and I hope to see your project continue in good directions.)

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.