Click here to Skip to main content
15,900,589 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionExe File encoding - http via vb.net Pin
Bart van Tuijl31-Mar-23 21:20
Bart van Tuijl31-Mar-23 21:20 
AnswerRe: Exe File encoding - http via vb.net Pin
Dave Kreskowiak1-Apr-23 5:18
mveDave Kreskowiak1-Apr-23 5:18 
AnswerRe: Exe File encoding - http via vb.net Pin
Richard MacCutchan1-Apr-23 5:42
mveRichard MacCutchan1-Apr-23 5:42 
AnswerRe: Exe File encoding - http via vb.net Pin
Eddy Vluggen1-Apr-23 6:28
professionalEddy Vluggen1-Apr-23 6:28 
GeneralRe: Exe File encoding - http via vb.net Pin
Bart van Tuijl2-Apr-23 5:13
Bart van Tuijl2-Apr-23 5:13 
GeneralRe: Exe File encoding - http via vb.net Pin
Richard Deeming2-Apr-23 22:05
mveRichard Deeming2-Apr-23 22:05 
GeneralRe: Exe File encoding - http via vb.net Pin
Bart van Tuijl3-Apr-23 5:49
Bart van Tuijl3-Apr-23 5:49 
GeneralRe: Exe File encoding - http via vb.net Pin
Richard MacCutchan3-Apr-23 6:13
mveRichard MacCutchan3-Apr-23 6:13 
GeneralRe: Exe File encoding - http via vb.net Pin
Richard Deeming3-Apr-23 6:44
mveRichard Deeming3-Apr-23 6:44 
GeneralRe: Exe File encoding - http via vb.net Pin
Bart van Tuijl3-Apr-23 7:33
Bart van Tuijl3-Apr-23 7:33 
GeneralRe: Exe File encoding - http via vb.net Pin
jschell4-Apr-23 6:19
jschell4-Apr-23 6:19 
AnswerRe: Exe File encoding - http via vb.net Pin
jschell3-Apr-23 6:09
jschell3-Apr-23 6:09 
QuestionBad Programming??... Pin
FreakNeck71631-Mar-23 4:09
FreakNeck71631-Mar-23 4:09 
So, I've done mainly VBc and C/C++ for embedded device, and a tiny bit of VC++. When .Net came along, after a while, it was often repeated that .Net allowed people to write bad code, but will still work. I was a stickler for following good programming form.

On one occasion, someone had ask a question about what the .Net compiler will do with [whatever code it was], and someone else chimed in saying something else like 'the compiler is smart and will optimize...'.

But, you know, I'm still a stickler for proper form, allocating vars and objects, properly destroying them, stopping any timers before program exit, etc. I guess, proper "cleanup" you could say.

So I'm working with some code the company hired a supposedly experienced programmer to write a program for the company that monitors devices it makes. Some of this is so appalling, that it looks like an absolute beginner would write. So the below chunk of code is one function he had written. He has this running in it's own thread, and it's a UPD listening socket. This is used to prevent multiple instances of it running, and to return from the system tray after it's been minimized to the tray. So this function is always running in it's own thread...

Private Sub udpThreadsub()
        While True
            Try
                udpcl = New UdpClient(UDPPORT)
                Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
                While True
                    Try
                        Dim rec = udpcl.Receive(RemoteIpEndPoint)
                        If rec.Length = 11 Then
                            Dim match = True
                            For i = 0 To 10
                                If rec(i) <> UDP_MSG(i) Then
                                    match = False
                                    Exit For
                                End If
                            Next
                            If match Then
                                Outoftray()
                            End If
                        End If
                    Catch e As Exception
                    End Try
                End While
            Catch e As Exception
            End Try
        End While
    End Sub


To me, this is some of the ugliest code I've ever seen. I mean, the compiler isn't THAT smart is it?

To me, this looks like the dim'd object will be created and sent to GC every iteration through the loop! But then again, I don't have an intimate knowledge of what the compiler will do with this. Will it just realize that it should just reusing these objects and not instantiate them and send GC as it appears they would?

I would have done the DIM's above the loops, and then reuse them in the code.

So is this some of the worse code ever seen (by me anyway) or is the compiler just 'that smart'?

Thanks in advance.
AnswerRe: Bad Programming??... Pin
Richard Deeming31-Mar-23 4:59
mveRichard Deeming31-Mar-23 4:59 
AnswerRe: Bad Programming??... Pin
Gerry Schmitz31-Mar-23 6:49
mveGerry Schmitz31-Mar-23 6:49 
AnswerRe: Bad Programming??... Pin
Dave Kreskowiak31-Mar-23 12:08
mveDave Kreskowiak31-Mar-23 12:08 
AnswerRe: Bad Programming??... Pin
jschell3-Apr-23 6:42
jschell3-Apr-23 6:42 
AnswerRe: Bad Programming??... Pin
Valley Kid31-Aug-23 19:37
Valley Kid31-Aug-23 19:37 
QuestionUpdate Settings in Winows Forms project Pin
Ron Mittelman27-Mar-23 8:06
Ron Mittelman27-Mar-23 8:06 
AnswerRe: Update Settings in Winows Forms project Pin
Gerry Schmitz27-Mar-23 11:48
mveGerry Schmitz27-Mar-23 11:48 
GeneralRe: Update Settings in Winows Forms project Pin
Ron Mittelman27-Mar-23 12:34
Ron Mittelman27-Mar-23 12:34 
GeneralRe: Update Settings in Winows Forms project Pin
Gerry Schmitz28-Mar-23 7:06
mveGerry Schmitz28-Mar-23 7:06 
GeneralRe: Update Settings in Winows Forms project Pin
Ron Mittelman28-Mar-23 11:57
Ron Mittelman28-Mar-23 11:57 
AnswerRe: Update Settings in Winows Forms project Pin
Ron Mittelman28-Mar-23 11:47
Ron Mittelman28-Mar-23 11:47 
GeneralRe: Update Settings in Winows Forms project Pin
Gerry Schmitz28-Mar-23 13:04
mveGerry Schmitz28-Mar-23 13:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.