Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Comments

andrgin andrgin
  • 10-4 Episode 12: Simplifying Your Code With C# 4.0

    1.) Optional Parameters are a really cool feature. The reason why VB.NET developers did not use it as often is because if you make a dll with your code and a C# developer used it then he had to type every parameter because he had no support for leaving it out.

    2.) It is not a question of design if you use method overloading or optional parameters. If you have a function with 10 arguments where you should be able to only specify those which you like then you would have hundreds of methods that only call other methods with default values. Often you choose only the most important combinations, but often you also have more then 20 methods.

    3.) Optional Parameters should not only accept constant values like true or false, but in most cases you need dynamic values. I have a function WriteProtocolEntry(Source as String, Message as String, Date as DateTime)
    Most Time Date is DateTime.Now. You can not default date to DateTime.Now so you have to use method overloading again.
    In many of my read/write Functions I have a Timeout. Defaulting it would be nice, but if you move the default value to a config file to change it very easy then you have to use method overloading again or default it to nothing and at the start of the method you write (in VB.NET):
    If Timeout Is Nothing Then
        Timeout=Config.Timeout
    EndIf

    If Timeout is an Integer even this is not possible and you have to default it to 0 or -1 or if it is a DateTime you could use DateTime.MinValue and hope that noone will ever write a Protocol Entry with 1/1/0000


    Another example of the advantage of optional parameters is the creation of Exceptions:

    Without the use of optional parameters you had to create 6 constructors:
    Public Sub New()
    Public Sub New(Message as String)
    Public Sub New(Message as String, InnerException as Exception)
    Public Sub New(AdditionalInfo as String)
    Public Sub New(Message as String, AdditionalInfo as String)
    Public Sub New(Message as String, InnerException as Exception, AdditionalInfo as String)

    Each Constructor only calls MyBase.New and I think MyBase.New() will do things like Me.New(Nothing,Nothing)
    With Optional Parameters you could use:

    Public Sub New(Message as String=Nothing, InnerExceptions as Exception=Nothing,AdditionalInfo as String=Nothing)
        MyBase.New(Message,InnerException)
        Me._AdditionalInfo=AdditionalInfo
    End Sub

    And if you want to compile it then you would notice that you have two constructors with the same parameter types (Message as String) and (AdditionalInfo as String).

    4.) For watching videos I use Media Player Classic and the KLite Codec Pack. With this player you can change the size of the video with the Num Pad.
  • 10-4 Episode 9: Visual Basic 10

    I dont want to say that you write bad code, only that it is not good style in most cases if you write such code.

    1.) Yes you can do it, but I dont think that it is a good idea. As I said before if I use Integer.Parse, then everyone can read in the stack trace what went wrong. In most cases I can put it to the user directly.

    2.) I also did such things. For example in my own TCP message protocoll. The first byte defines the Type of the Message, the next 4 bytes the length and the rest is the data. The messagetype is an enum that is edited for each application individually. That is the reason why you can define an Enum as a byte, integer and so on and I think it would be a good idea to also allow other types because in some cases you need it. You often get some error or status codes that are not always integers, but also bytes, strings etc.

    3) If you write a Console Application this is an option, but if you only have a GUI, than this would be a bad idea because the user will never notice it and you will work with wrong data. Making a message box everytime is also not good every time because if you use it in a timer that is executed every 100ms then it also be not really good Big Smile
    I prefer throwing an Exception. For example: Throw New ArgumentException("Error when doing action xyz: Variable x <> 0")
    If the error comes because of wrong data from the user, then he will in most cases know what he did wrong.

    4) I also use the 0 value als Null Value in some cases. For example when I am writing a performance database application and want to get the ID of a column like "select Person_ID from Person where Person_Firstname='John' and Person_Lastname='Doe'" and Person_ID is an identity(1,1) then can not be 0, but if I want to set the value to 0 I explicitely do it. "Dim x as Integer" means that I declare a variable x that has not a value yet. If I write "Dim x as Integer=0" then that means, that I set the initial value to 0. Both statements produce the same output, but it is clear what the convention is.

    5) I am also working alone and defining the conventions myself, but you also have to think of the poor guy that will have to debug your code in 5 years when you are maybe having another job or maybe you are the poor guy and you dont have an idea what you did.

    6) If I write Dim x = 5 then the compiler automatically makes an Integer, but maybe you wanted an UInteger to not allow negative values because it make no sense or an Int64 or maybe you want to have a double. Maybe you start with Dim x=3.14 and then change the 3.14 to 3. This will not only change the initial value, but also the full logic of the program if you write x=47.11 later and then you have problems because only 47 is saved.

    7) In your example Both Toolbars = 3 and this is the same as Horizontal + Vertical, but I do not know if this was the intention of the person who defined the values. For example if you use the SerialPort Class with the Stopbits Enumeration. 0=0 Stopbits, 1=1 Stopbit, 2=2 Stopbits, but 3= 1,5 Stopbits.
  • 10-4 Episode 9: Visual Basic 10

    It is a convention that you use properties for data access to other classes. It is good style to use Properties because you can simply change it.
    If the Property is called FirstName then the variable is called _FirstName. If you see a variable if _ at the first character you know that it is a class member.
    I also started to put a Me. in front of every thing I access in the current class like variables, properties (if used from internal code) or functions.
  • 10-4 Episode 9: Visual Basic 10

    Are you sure?? sometimes I am sure about the result and I even write things relying on VB implicit:
    Dim i As Integer = "45"
    or
    TextBox.ScrollBars = 3-2
    TextBox.IsMultiLine = 5
    I never had bugs with it and it's very useful, I would even tell u that this is one of the reasons I didn't leave VB after the un-implementing auto props flop in 2008 ver.

    Oh, another cool example:
    Sub Form_Load(sender As Form, e As EventArgs)
    'now you have full intellisense, in cs you have to explicitly cast it.

    But all this is in my humble opinion and experience I might be wrong.
    thanks

    1.) Why should I write things like i as Integer="45"
    If 45 is a constant, than I could leave out the " and if it is a function that returns a string, then I always use Integer.Parse() because there can be an exception when converting. If I am sure there will be only an integer from the function I declare the return type as integer and parse it in the function itself.

    2.) And you really think that anyone can read that code if you write TextBox.ScrollBars = 3-2 You maybe know that 3 means both scrollbars and 2 mean vertical, but if someone else has to debug your code 5 years later he will have enough problems following the meaning of the code itself so he can not look up a constant every time. If you want horizontal scollbars then write Scrollbars.Horizontal

    3.) If you do not set things explicit you will end up where you were in the old VBA with option explicit off. You mistype a variable and it declarates a new one automatically. You write a function that has a syntax error, but dont bother you dont compile it so you will not notice it for a long time. Everything is also returned as Variant and you build super code and if you are debugging it you will notice that it will not work because a function takes only an integer or double and not a date.

    4.) I also write code like
    If MessageHandled = True Then
      'Do Something
    EndIf

    It is not because I dont know that I can leave the = True out, but I think it is better readable.
  • 10-4 Episode 9: Visual Basic 10

    1.) I think multiline lambdas are a good thing. You can make much more things like writing a function like CatchAndProtocolException.
    I am building a try catch block around every function that is started directly from the GUI and catch the Exception whatever it is. Then I protocol it and give a message box. I am making software for special hardware where you can not test at home and if you ask 2 of the customers what happened before the error I am getting 3 completely different answers, so exceptions that are written to a protocol file with using the .pdb file to get the line number ist the only way to find some bugs.
    Another Function could be ExecuteAndProtocol which takes a Message and a Lambda of the code. This can really be useful some time when my code contains more protocol entries then real code.

    2.) I think the auto implementing properties was an invention of the C# guys. Making Public Variables is not good style. The programmer writing the external code does not need to know which property only gives back a variable and which does a calculation as long as the calculations are simple (I am always having trouble which some COM Servers that have read properties that do write operations and adding a watch changes the output of the program or some GUI that are doing IO operations with a timeout auf 10 seconds).
    Is there a way to make an auto implementing property readonly or writeonly. I saw in a previous video that you also get a private variable with a leading _. This is the most important case that you have a private variable that you make readonly available to external code.
    It would also be good if you could have an option to make the getter auto implementing and the setter not or the other way round.

    3.) I think that you always should explicit declare a variable and not write code like "Dim counter=5"
    In this case it should be easy to read, but if you have not 5, but another variable oder even a function you can not see very easy which type of variable you have. If you are using a function and then change the return type you maybe are maybe getting an error much later.

    4.) Are there some of this features available when targeting the .NET Framework 2.0 or 3.5? The problem is that nearly everybody has .NET 2.0 because he will need it everywhere, but only few people are having .NET 3.5 and if .NET 4.0 is new it will be worse, so most of my programs will target .NET 2.0. In many cases the customer does not have the rights to install a new .NET Framework and often I would not do it even if it would be possible because it is a big change to the system and if the installer fails (which happens sometimes) the whole system of the customer would have to be reinstalled and if this happens on the server I have got a big problem.

    P.S.: What VB really needs is a way to combine the "For To" with the "For Each" loop. I always start with a "For each" loop and end up with a "For To" loop because I need an Index (for example if I am taking data from one array/collection to the other). There should be a way in the "For Each" loop to get the current loop count.
  • 10-4 Episode 6: Parallel Extensions

    When I simply use the Parallel For loop how does the Parallel library know how many threads it should create at a time.

    If you only have code that uses the CPU oder memory it is the number of cores, but what does it when there are more IO operations.

    1.) If you have got an application that does CPU calculation 50% of the time and 50% are IO operations like waiting for a another computer in a client/server situation. Then you could use 2 time the amount of cores. If you only have 10% CPU calculations and 90% IO (like a web server or another server application that is most time waiting for the user clients or user inputs). It would not be a good idea to only use 8 threads on a quad with two Quad Core Xeons. You could only have 8 users working on the server at a time. There you should use at least 100 threads.

    2.) You could also have a program that calls another program (for example with the shell command and set wait to true). Then you cant know if it is a program that only waits for the user on another client to press the submit button or its an CPU intensive application like my multi core optimized audio encoder that is calling lame on several threads with different files. Then 100 threads would kill the computer if you do not have enough RAM. For the .NET Framework it is an IO operation but in reality it is a CPU only task.

    3.) What does the class if you already have multiple threads and each thread does a parallel for loop (take another server where you created the connections with tcplistener.accepttcpclient and started each tcpclient in his own thread. If you have 16 cores and 32 client connections you would make too much connections again. Then you should only use 1 thread per client and if only 1 client is connected then you should use 16 threads.

    4.) If I am using an application where the load is on an external network share. How does the .NET Framework know how man parallel operations can be done at once.

    I think the parallel for is a good idea but it will never replace manual creation of threads.
    Also debugging is more complicated. If I create the thread on my own I can give it a name and find it again very easy. When using network streams I set the threadname to ip and port number (127.0.0.1:4711).
  • 10-4 Episode 5: Code Focused in Visual Studio 2010

    1.) Yes please stop the PIP or find a better position. You often cant read anything.

    2.) I dont think its a good idea to use hundreds of external tools. The most important features should be included in VS directly. If there is a nice feature that another application used, then why not copy it. On the other side I dont see a problem if someone else copies a feature of VS like Java did with the for each loop from C#.
  • 10-4 Episode 5: Code Focused in Visual Studio 2010

    1.) I think its better to concentrate on the content and not on the quality of the video. If I like a professional marketing video I go to Youtube and watch Steve Ballmer (developers, developers, developers) Big Smile

    2.) Is there a way to change the color of the marked references, because in the current color I cant see anything.
    I love huge monitors, but unfortunately you can only get them with a cheap TN Panel if you dont want to pay >1K $. So I can not really decide between white and a very light gray like in this case (tested with my 28" Hanns.G at home, but also with my cheap standard 22" Acer monitor at work), if you are looking from the wrong side and I think I am not the only one.

    3.) Making the editor in WPF is a good thing. I love this new zooming function. I was searching for this the whole time (and maybe also buy larger monitors to get more resolution and more code on the screen).
  • 10-4 Episode 2: Welcome to Visual Studio 2010

    1.) I also think that the Powerpoint presentation was useless. It sounded like the typical marketing stuff provided by Microsoft all the time like "Windows Vista ist faster, better, easier to use than all before. It has much more networking support etc. but no concrete information what really changed or how to use it. Sentences like "Accessing data is much easier" sound very nice, but that is also true for the new elevator up to the library.

    2.) I also think that there should be an easier way to customize the start page. For a classical Linux user who likes modifying his configuration files with vi and compiling old C code with gcc using the command line and debugging the code with massive use of printf and when sitting in front of windows they spend half an hour for finding the command line options for winzip instead of simply double clicking the file this will be absolutely fine, but most users use Visual Studio because they do not want to do that stuff. For Web Developers this should be no problem, but for simple Windows Application designers like me (many of my applications have only a close button and an exception log) WPF is completely new. I agree it is also not good if you only have a GUI and nearly no options. I think the best way is a GUI that allows you to customize the most important features that generate XAML code like it is done in Access. You can do much by simply clicking without spending weeks to learn it and if you want to code something you can do it as well like editing a query in SQL etc.
  • 10-4 Episode 1: Working with the Visual Studio 2010 CTP VPC

    1.) Start Virtual PC, but do not start a Virtual Machine
    2.) Go To File=>Options
    3.) Click on Keyboard
    4.) Click on the text box with the host key
    5.) Type in a new key

    For the German layout I think the right Windows key should be best, because you do not need it.

    You can find the different keyboard layouts here (works only with Internet Explorer): http://www.microsoft.com/globaldev/reference/keyboards.mspx