Classes vs. Modules

  • Thread starter Thread starter Zytan
  • Start date Start date
neither is worse than the other?

classes are more verbose, slower performance and no tangible benefit
 
my so called 'module encapsulation' supports code reuse
it supports private variables, it supports public variables.

I could give a shit about your premise--- that global vars are bad.

global vars are NECESSARY and HELPFUL and possibly a last resort-- but
infinitely more powerful than NOT BEING ABLE TO USE GLOBAL VARS

it's like a parachute.. if you could wear a parachute every time you
took an airline flight-- sure it might be necessary; sure it might be
a pain in the ass; sure other people might laugh at you

but what happens the one time that your airplane door gets blown off
but what happens the one time that your airplane roof gets blown off

and you're the only one with a parachute because these people said
'parachutes are frowned upon'

I don't agree with the blanket statement that global vars are evil.
global vars save a lot of effort for a lot of reasons.

and you class fags dont have the option so STFU and don't bitch about
my parachute

in some cases; it saves a lot of effort and i'm sorry that your
computer science professor was egocentric-- but he was WRONG

C++ _LOST_ the war, VB _WON_ the war
and then MS threw the game because MS; the steward of the VB family--
screwed us all by inventing visual fred
 
who gives a crap?

it is slower; when the single argument that they had is that it made
things faster.

DOTNET LOSES AGAIN
 
Hello Aaron,
having a car class and a bicycle class and both of them have a weight
function.. so I've got to reuse some code but I CANT I need to copy
and paste the code in order to make my maintenance job harder.

RIGHT?

Wrong. You don't have to copy and paste, that's the good thing of it.
You just inherit and it is just there.

Example:

'The class definitions - just for reference
Public Class Vehicle
Private vWheels As Integer = 0
Public Property Wheels() As Integer
Get
Return vWheels
End Get
Set (ByVal Value As Integer)
If Value<0 Then
Err.Raise(450)
Else
vWheels = Value
End If
End Set
End Property
End Class

Public Class VehicleWithEngine
Inherits Vehicle
Private vHorsePower As Integer = 1
Private vCylinders As Integer = 1
Public Property HorsePower () As Integer
Get
Return vHorsePower
End Get
Set (ByVal Value As Integer)
If Value<1 Then
Err.Raise(450)
Else
vHorsePower=Value
End If
End Set
End Property

Public Property Cylinders As Integers
Get
Return vCylinders
End Get
Set (ByVal Value As Integer)
If Value <1 Then
Err.Raise(450)
Else
vCylinders=Value
EndIf
End Set
End Property
End Class

Public Class Car
Inherits VehicleWithEngine
Private vDoors As Integer
Public Property Doors () As Integer
Get
Return vDoors
End Get
Set (ByVal Value As Integer)
If Value<1 Then
Err.Raise(450)
Else
vDoors = Value
End If
End Set
End Property
End Class

'End of class definitions

Private Sub ABC()
Dim v As New Vehicle
Dim vwe As New VehicleWithEngine
Dim c As New Car

v.Wheels = 1

vwe.Wheels = 2
vwe.HorsePower = 30
vwe.Cylinders = 1

c.Wheels = 4
c.HorsePower = 110
c.Cylinders = 4
c.Doors = 3
End Sub

As you can see from the sub ABC, all variables have the "Wheels"
property (inherited from Vehicle). In addition vwe and C have the
properties "HorsePower" and "Cylinders" (from VehicleWithEngine) and
only c has Doors (from Car).

How you write the data into those variables is not relevant (if you do
that from a database or a user enters it or whatsoever).

Let's say that you find a bug in one of the classes. You just have to
identify the class where the code originates in order to solve the bug
for that class all classes that inherit from it. If you copy and paste
code, then you have to search all routines which use the same code.
Class Car
sub weight
'lookup weight in the database
end sub
End Class

Class Bicycle
sub weight
'lookup weight in the database
end sub

End Class

and don't bitch about how I should inherit both from a common vehicle
class; because uh-- shit's too complex for one way inheritence; sorry.
it just doesn't have any benefit for me; I'd rather have a module with
weight any day of the week.

Sorry, but what's so difficult to add the Weight property to the Vehicle
class?

Public Class Vehicle
Private vWheels As Integer = 0
private vWeight As Decimal = 0
Public Property Wheels() As Integer
Get
Return vWheels
End Get
Set (ByVal Value As Integer)
If Value<0 Then
Err.Raise(450)
Else
vWheels = Value
End If
End Set
End Property

Public Property Weight() As Decimal
Get
Return vWeight
End Get
Set (ByVal Value As Decimal)
If Value<0 Then
Err.Raise(450)
Else
vWeight = Value
End If
End Set
End Property
End Class
unnecessary code maintenance is not necessary
Exactly that's where classes help you. They code becomes easier to maintain.
and how when I'm trying to explain to a C# friend why I use a module;
he's like 'uh I dont get it'

I'm also from the classic VB line and used modules a lot. Nevertheless,
the classes in VB.NET are helpful.

Best regards,

Martin
 
Zytan said:
I've grown tired of monospaced fonts and moved to variable width
fonts, and smaller fonts, and moved all my toolbars out of the way to
essentially show line lengths 3 times or more the length they normally
would show. This helps ease the issue of readability.

I am not writing the code for myself. It needs to be readable and easily
maintainable for other people reading and extending it.
Importing everything is a huge no-no.

I do not import anything, but I import any namespaces containing types I am
using. So reading the 'Imports' section shows which namespaces are used.
 
With inheritance you can do stuff like this:

Dim arrtxt() As TextBox
arrtxt = New TextBox(){Text0, Text1, Text2,...)
For Each txt As TextBox In arrtx t: AddHandler txt.Leave, AddressOf someProc
: Next

In VB6 it would be this:

Private Sub Text0_LostFocus()
dosomething
End Sub

Private Sub Text1_LostFocus()
DoSomething
End Sub
....

My code has shrunk nearly 30% by switching to VB2005 from VB6, plus the
VS2005 IDE catches more errors than anything I have ever seen. It is almost
impossible to write buggy code (at the compiler level) in VS2005 (VB, C#...)

As far as running slow goes, if your clients are using antiquated hardware,
then yes -- you are resigned to using antiquated technology. But if they
are using current hardware, then VS2005 will run just as fast as the old
stuff. One line of code in VB2005 packs way more punch than a line of code
in VB6, so yes, you will need a bigger engine to run it.
 
neither is worse than the other?
classes are more verbose, slower performance and no tangible benefit

We were talking about dependencies. I will not discuss something I
did not say. Please keep on topic.

Zytan
 
zytan
is not your method more verbose?

Yes.

And it's more accurate.

This helps for people that are new to the framework. As I get used to
it, I'll stop being verbose. The verbose-ness is not that bad using
intellisense, since the amount of typing is very little. Yes, not as
minimal as without all the explicit typing, but much more minimal that
people first realize. It hardly slows me down. And when it does, it
helps me learn. So, it's ok, for now.

Zytan
 
I've grown tired of monospaced fonts and moved to variable width
I am not writing the code for myself. It needs to be readable and easily
maintainable for other people reading and extending it.

Good point.

I do not import anything, but I import any namespaces containing types I am
using. So reading the 'Imports' section shows which namespaces are used.

(Just to be clear, I said 'no-no' for beginners trying to learn the
framework, not seasoned experts.)

Yes, understood. It shouldn't be so bad if it is just for types. A
few of these things are imported by default, anyway.

Zytan
 
it is slower; when the single argument that they had is that it made
things faster.

I think they meant development time.

Go program a winsock VB6 app and compare it to my VB .NET.

See you next year.

Zytan
 
Not sure if you originally said this Zytan, but whoever did, that's just
plain wrong.

If you don't like importing everything, fine, then don't, but that doesn't
make it bad convention or a best practice not to do it.

I agree 100% with Herfried on this. Import what you are using (or in the
case of C#, use "using" statements on what you are importing). Do it at the
top of the code. Unless there would be a naming collision, use the
unqualified type name.
 
tom

well you can either duplicate your code in multiple classes
or make a functions class and instantiate the class before using the
methods within another class right?

either way you got dependencies and no benefit

A module in VB.NET is a class (and AFIK, was in VB6 as well). Do you
understand the concept of a shared method? You do not have to
instantiate anything. For example:

module ExampleModule
public sub DoCoolStuff ()
' do cool stuff
end sub
end module

and

class ExampleClass
private sub New ()
end sub

public shared sub DoCoolStuff()
' do cool stuff
end sub
end class

are functionaly equivalent. You do not need to instantiate
ExampleClass to call DoCoolStuff. You call it like:

ExampleClass.DoCoollStuff()

Dependencies are not an issue unless you code them to be an issue -
and the same applies to modules. Also, in these cases, there really
isn't going to be a performance difference - ExampleModule is
essentially going to turn into ExampleClass at compile time.

You also seem to be under the false impression that instantiating a
class multple times results in duplication of the code of that class
in memory.... It does not. All isntances share the same code. All
instance methods take a hidden pointer to the current instance (this
is generated by the compiler). So, if for example DoCoolStuff was not
declared as shared in ExampleClass, then what you would end up at
compile time would essentially be something looked like:

Sub DoCoolStuff (ByVal Me As ExampleClass)

HTH
 
no DUDE you are wrong

I can inherit in ONE DIRECTION

but what about when I have a house and a car that has a DOOR? then I
need to copy and paste

duplicate code is not efficient; sorry classes are for fags
 
ok.

here you go.

I have a text 'parser' class and then I inherit that into 15 other
classes

strainer
sifter
shovel
magnet

etc

yeah; i can have _SOME_ common methods.. it is _SOMEWHAT_ nice.
but it doesn't go far enough; it doesn't help me to reuse code in 15
different classes.

I wish I had my laptop here to show you my real examples.



using classes is totally inefficient; I've got a dozen MS press books
that admit that using classes is slower-- if you want to send me new
copies of these books that are corrected; I would be glad to change my
opinion.

But MS doesn't fix bugs; all those dipshits do is run around like a
bunch of retards; trying to sell us on new version

and I understand the perils of maintaing code in multiple places.

THAT IS WHY I DO NOT USE CLASSES.

my apps run faster than yours, classes do not give me any new
functionality

I don't see the point in newbies giving a crap about classes; sorry.

but performance trumps everything else.
and classes are on the losing side.

they are MORE VERBOSE and SLOWER.

end of story
 
I mean seriously here

C# is faster than VB in like ONE situation that is never practical;
and all of a sudden; everyone flocks to C#

PROGRAMMING WITHOUT CLASSES IS MORE MAINTAINABLE, FASTER AND LESS
VERBOSE.

Are you guys from MARS?
 
Zytan

I am sorry you admit that it is more verbose; and yet you still use
classes?

WHAT THE HELL IS WRONG WITH YOU?

classes can't inherit _JACKSHIT_

sorry

but i militantly disagree with anything that is a feature in VB
DOTNET; sorry I mean VB 2005

classes make shit run slower; they involve more typing.

if you use them you are a stupid ****ing yesman, selling your soul for
the wrong causes


**** MS AND **** CLASSES

80% of Vb6 developers 'never needed a class'

UNNECESSARY CHANGE IS NOT _SEXY_

UNNECESSARY CHANGE IS NOT _HELPFUL_

UNNECESSARY CHANGE IS NOT _NECESSARY_
 
Scott;

if you want to talk about C# you can go **** some monkeys in Africa

come talk about c# to my face, BITCH


this is a VB newsgroup; mother ****er don't even mention that
language; it was never created.

DIPSHITS SHOULD HAVE MADE VB BUGFREE BEFORE PULLING RESOURCES OFF OF
VB7.

AS IT IS; VB7 and C# have been buggy as hell; so mother ****ing take
your crap and shove it up your ass

bitch


I've got MS press books that state that classes involve more verbosity
and slower performance.

if you guys don't accept these as facts; then you can **** yourself.

if you do accept it as fact and you keep on using classes then you can
still **** yourself
 
Back
Top