Improving myself questions.



  • I am a self-taught programmer that started out in classic ASP and moved to .NET when it came out.  I have done about five "big" we projects (VB.NET, ordering process, business analytics) but they have all be just me by myself.  I am always able to do what I need but I fear that since I have never been in an environment with other programmers that I might not be doing everything the best way it could be.  What sites do you recommend (other than this one) where I can not only view code but learn why it's done a certain way? 

    I want to be programming as best I can with the right methods even though they might be overkill for the projects I am working on so that when I get in a company with multiple programmers I'm not the WTF guy.

     Here are a couple questions of the type I have:

     1)  When should I be using data adapters?  Right now I usually have only one or two editing records pages so I'm using Stored Procedures for the page and it's working fine.  Data adapters seem to be overkill and more code for simple queries and a single update page.  I know the theory behind them but what is a real world scenario where I should be using them?

     2)   I have a Tools class where I put my personal functions.  Two are the following to ALWAYS return a string and decimal.  Is this the correct way of doing it?  I use this always when I'm grabbing values from the database (into variables and textboxes, etc.).  For example tbxName.Text = Tools.ConvertString(objDataReader("Name")).  FYI, I also put constraints and such on the fields that never should be null in the database, etc.

    Public Shared Function ConvertString(ByVal myObject As Object) As String
                Dim strString As String = ""
                Try
                    If myObject Is Nothing Then
                        Return strString
                    Else
                        strString = CType(myObject, String)
                        Return strString
                    End If
                Catch ex As Exception
                    Return strString
                End Try
    End Function

    Public Shared Function ConvertDecimal(ByVal myObject As Object) As Decimal
                Try
                    Dim decNumber As Decimal = Decimal.Parse(myObject.ToString)
                    Return decNumber
                Catch ex As Exception
                    Return 0
                End Try
      End Function

     


  • ♿ (Parody)

    Stack Overflow is a pretty good resources.  Have you tried there?



  • Hadn't heard of it.  Just started to look.  Should have joined communities/sites a long time ago.  Thanks!



  • This is my typical pattern when reading values from a database query (converted to VB from memory since I do C#).

    Public Function GetSomething() As List(Of Something)
        Dim list as List(Of Something) = New List(Of Something)()
        
        Using dbConn as SqlConnection = New SqlConnection(connString)
            dbConn.Open
            
            Using dbCmd as SqlCommand = New SqlCommand("GetSomething", dbConn)
                dbCmd.CommandType = CommandType.StoredProcedure
                
                Using reader as SqlDataReader = dbCmd.ExecuteReader
                    Do While(reader.Read())
                        Dim something as New Something()
                        
                        If (reader.IsDbNull(reader.GetOrdinal("String1")) Then
                            something.String1 = reader.GetString(reader.GetOrdinal("String1"))
                        End If
                        
                        If (reader.IsDbNull(reader.GetOrdinal("Decimal1")) Then
                            something.Decimal1 = reader.GetDecimal(reader.GetOrdinal("Decimal1"))
                        End If
                        
                        list.Add(something)
                    Loop
                    
                    return list
                End Using
            End Using
        End Using
    End Function

    Now there are two schools of thought about interacting with databases, those that use DataSets/DataTables and those that use lists of custom classes.  I generally use custom classes as I find DataSets bloated.  As such, I pretty much can't use data adapters.  I bind my controls to a bindingsource and set its DataSource property to a BindingList(Of SomeObject) retrieved via a method from a Data Access Library.

    As for the ConvertDecimal function, I'd look at the Decimal.TryParse method as it doesn't throw an exception but returns a Boolean as to whether the parse succeeded or not.  



  • @lpope187 said:

    I generally use custom classes as I find DataSets bloated.
    Wouldn't want to have all of those extra DataSet features getting in your way, eh? DataSets are designed to store relational data. If you have relational data, and aren't writing an embedded system (and since you're using VB/C# we know you aren't), why would spend more effort to implement a fraction of the functionality already afforded to you by DataSets?



  • @MyNameIsLoki said:

    I am a self-taught programmer that started out in classic ASP and moved to .NET when it came out.  I have done about five "big" we projects (VB.NET, ordering process, business analytics) but they have all be just me by myself.  I am always able to do what I need but I fear that since I have never been in an environment with other programmers that I might not be doing everything the best way it could be.  What sites do you recommend (other than this one) where I can not only view code but learn why it's done a certain way?
    Well, I have two thoughts, such as they are:

    1) Have you been to school for this? Granted, you're not going to find me singing too many praises on what is taught in schools, but at least you walk away with the framework, and hopefully, some team projects.

    2) Code Complete, 2 - ISBN: (-10) 0-7356-1967-0 (-13) 978-0-7356-1967-8 web: http://www.cc2e.com/ wiki: http://en.wikipedia.org/wiki/Code_Complete Amazon. Never read edition #1, but AFAICT #2 is a more current version of #1. Buy it, read it, grok it. This is not a book about how to write code in a particular language, or how to use a particular construct correctly, but it is about how to work as a team, and the sort of thing we should all do and strive to be as developers. Great book.

    Now, my question to the board, who has a similar (or if it's possible, a better) book to go along with CC2? Or who out there thinks I'm totally off my rocker for suggesting CC2?



  •  "I fear that since I have never been in an environment with other programmers that I might not be doing everything the best way it could be"

     

    I was in the same situation about 12 years ago.  My company was full of mainframe programmers and I was the only Windows developer (and I didn't have a lot of experience outside of a couple of courses).  I hacked away the best I could for a couple of years, and I was certain that the way I was doing things was amatuerish.  Then I got another job where I had to maintain some code and port it to VB6 from VB3.  This code was so sloppy (everything in 1 procedure with all kinds of Gotos), it made my code look textbook.  Then I got another job and the code there sucked too (they were fond of using People's names as variables:  For Jeff = 1 to Steve...)

     

    So, the moral of the story is that if your code works and it is not egregiously bad, then it is actually pretty good.  Any place that hires you will either have you work by yourself, maintain horrible code, or (if you hit the jackpot) will have their own best practises which they will teach you.

     

    So, I'd tell you not to worry too much over the style of the code.  Just make sure it is organized well, and that if you have to revisit it in 3 years you can figure out what it is doing without pulling your hair out.



  • If I use the "Fresh vegetable" setting on the microwave to reheat my mac & cheese, does that count as eating healthy?


  • FoxDev

    Goddamnit @whargarbl !



  • @accalia fun fact: I did not get a notification for your post.

    I bet @whargarbl did, though.



  • @accalia also, I think you meant @wharrgarbl.


  • FoxDev

    @anotherusername said in Improving myself questions.:

    @accalia also, I think you meant @wharrgarbl.

    he has too many alts for me to keep track of.


  • Grade A Premium Asshole

    @apapadimoulis said in Improving myself questions.:

    Stack Overflow is a pretty good resources.  Have you tried there?

    My how things have changed...



  • @accalia that's was the idea. It would work if it wasn't for those meddling kids (admins)


  • FoxDev

    @wharrgarbl said in Improving myself questions.:

    @accalia that's was the idea. It would work if it wasn't for those meddling kids (admins)

    yeah, no.

    you ain't subtle.


Log in to reply