6 Replies - 3228 Views - Last Post: 09 June 2016 - 11:59 PM Rate Topic: -----

#1 maceysoftware  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,494
  • Joined: 07-September 13

Not really "bad" just Pointless

Posted 18 May 2015 - 06:59 AM

So recently i found this little gem...

    Private Function FileExist(path As String) As Boolean
        If System.IO.File.Exists(path) Then
            Return True
        Else
            Return False
        End If
    End Function


As you can imagine i just fell off my chair laughing say whats the point in that!
Is This A Good Question/Topic? 1
  • +

Replies To: Not really "bad" just Pointless

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5074
  • View blog
  • Posts: 13,697
  • Joined: 18-April 07

Re: Not really "bad" just Pointless

Posted 23 May 2015 - 09:27 AM

Well as funny as it may be it is not totally crazy for a number of reasons...

1) It can be used to rename some functionality. While they don't do that there, you could have named it "DoesFileExist" and make it more descriptive.
2) It provides a point where later you could actually add in your own error handling or centralized logic.
3) The fact it is private makes it so that it will belong to a class. So instead of calling the system version directly, you could use it within the class itself. If they had made it public it would also have allowed them to use that function from other classes where it might make sense...

Dim someClass as New MyClass()

someClass.FileExists(aFileName)



What I want to get across most importantly is one key idea... while it may seem like overkill most of the time, there may be reasons where you have a one line body function that does little more than wrap around an existing function. You may run into these things when it comes to interfaces. If "MyClass" in my example was a library of file manipulating functions you may want a method called "FileExists()" for completeness. Even if it just wraps around the existing system version. Now don't expect to run into it every day, but I have seen cases where it does make sense... again usually for consistence on interfaces to a class.

:)
Was This Post Helpful? 0
  • +
  • -

#3 maceysoftware  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,494
  • Joined: 07-September 13

Re: Not really "bad" just Pointless

Posted 24 May 2015 - 04:07 PM

Hey Martyr2,

I do get what your saying in all your points however the developer did none of these. Which is why I posted it.

As you said he did not rename the name to be more descriptive.

If indeed this was done in a central location then yes I am in complete agreement (I would also fully support this) however this code was within not just one form, or two forms but three separate forms, the code identical in each.

I myself have seen cases where is does make sense and have even written my own which wrappers the file exists system method however never like this, maybe I didn't put all the facts out there, sorry again this xD
Was This Post Helpful? 0
  • +
  • -

#4 Recoil  Icon User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Re: Not really "bad" just Pointless

Posted 09 June 2016 - 08:17 PM

No joke, I have used that exact function before. It's great...hobby coding is awesome! >.<
Was This Post Helpful? 0
  • +
  • -

#5 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: Not really "bad" just Pointless

Posted 09 June 2016 - 08:27 PM

Martyr2 makes a good point, but I still contest this code. Is the following not syntactically correct and more concise?
Return System.IO.File.Exists(path)


Was This Post Helpful? 0
  • +
  • -

#6 Recoil  Icon User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Re: Not really "bad" just Pointless

Posted 09 June 2016 - 09:28 PM

It is, however looking through some code I wrote just a few years ago I saw that exact function. Brings back memories :)

And I was still to lazy to do anything about it because I still have plans for it...one day!
Was This Post Helpful? 0
  • +
  • -

#7 maceysoftware  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,494
  • Joined: 07-September 13

Re: Not really "bad" just Pointless

Posted 09 June 2016 - 11:58 PM

I am in agreement with everything Martyr2 Said, if they renamed the function to make it more descriptive great, if they put it in a central location for everyone to use this same functionality great, if they expanded it to do more than just a simple if - great.

It's now a year on the code is exactly the same, it now exists in 7 forms, not the originally 3 and the code is identical.

e_i_pi - i am in also in complete agreement with you, that is exactly what the function should do if it is not going to be expanded, or even until it is. I did help said developer a few months back to implement some authorisation rules, whereby we a function which did a few things but did it on a single line so like:

Return Something.Something AndAlso Something.AnotherThing



When i went to help him again a week later i notice this was split out again with the answer of he can't get his head around when its on one line?

So i guess i can kind of understand that, as long as he doesn't go changing my code to "Make more sense", i am now fine with this.

This post has been edited by maceysoftware: 10 June 2016 - 12:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1