|
You have no idea how glad that makes me! I don't think she'd be too happy herself - she has been dead for years...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I wonder if the code at some point had some different instructions, possibly logging, for the null and non-null cases?
|
|
|
|
|
It's just a little fix to get a value and not a Nan (french-glish comments! ). Why do simple ?
|
|
|
|
|
Just for your pleasure, I have opened a random VB 6 program from my archive to post some horror.
This is from a program which purpose was to teach user doing simple math tasks, that is multipying, dividing, adding and subtracting. Well it worked, but I still don't know a multiplication table by heart.
I suppose Command1 was a "Start" button. Of course, the same code was copied to a "Next task" button.
Private Sub Command1_Click()
x = InputBox("Enter a name or a nick:", "Name?!", nz)
If x = "" Then Exit Sub
nz = x
kon = False
Command3.Enabled = True
Command4.Enabled = True
dzial.Interval = Text4 * 1000
odp.Interval = Text5 * 1000
Label1 = ""
Label8 = ""
Label1.Visible = True
il = 0
oc = 6
' Combo2.AddItem "0 - First component (denary)"
' Combo2.AddItem "1 - Both components (denary)"
' Combo2.AddItem "2 - First component (hundredth)"
' Combo2.AddItem "3 - Both components (hundredth)" <== whatever that means... ;)
If Check1 = 1 Then
ul = Combo2.ListIndex
Else
ul = 124
End If
1:
Randomize
d1 = Int((Text2 + 1) * Rnd)
Randomize
d2 = Int((Text3 + 1) * Rnd)
Randomize
If Check2 = 1 Then
rd = Int((4) * Rnd + 1)
Else
rd = Int((2) * Rnd + 1)
End If
If d1 = 0 Or d2 = 0 Or rd < 1 Or d1 = d2 Or d1 = 1 Or d2 = 1 Or rd > 4 Then GoTo 1
Randomize
If ul = 0 Or ul = 1 Then
a = Int((9 + 1) * Rnd)
a = Left(a, 1)
c = Str(d1)
c = c & "." & Str(a)
d1 = CDbl(c)
End If
If ul = 1 Then
a = Int((9 + 1) * Rnd)
a = Left(a, 1)
c = Str(d2)
c = c & "." & Str(a)
d2 = CDbl(c)
End If
If ul = 2 Or ul = 3 Then
a = Int((99 + 1) * Rnd)
a = Left(a, 2)
c = Str(d1)
c = c & "." & Str(a)
d1 = CDbl(c)
End If
If ul = 3 Then
a = Int((99 + 1) * Rnd)
a = Left(a, 2)
c = Str(d2)
c = c & "." & Str(a)
d2 = CDbl(c)
End If
If rd = 1 Then
w = d1 * d2
Label1 = d1 & " times " & d2 & " =?"
ElseIf rd = 2 Then
w = d2
Label1 = d1 * d2 & " divided by " & d1 & " =?"
ElseIf rd = 3 Then
w = d1 + d2
Label1 = d1 & " add " & d2 & " =?"
ElseIf rd = 4 Then
w = d1 - d2
Label1 = d1 & " minus " & d2 & " =?"
End If
dzial.Enabled = True
odp.Enabled = True
Command4.Enabled = False
Frame1.Enabled = False
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Command2.Enabled = False
End Sub
A correct answer was stored in a global variable "w".
A user could even set adifficulty level!:
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "Easy"
Text2 = 10
Text3 = 12
Text4 = 9
Text5 = 28
Text6 = 11
Check1 = 1
Combo2.ListIndex = 0
Case "Elementary"
Text2 = 9
Text3 = 9
Text4 = 3
Text5 = 20
Check1 = 0
Combo2.ListIndex = 0
Text6 = 14
Case "Medium"
Text2 = 13
Text3 = 14
Text4 = 14
Text5 = 35
Text6 = 15
Check1 = 1
Combo2.ListIndex = 1
Case "Hard"
Text2 = 15
Text3 = 15
Text4 = 30
Text5 = 50
Text6 = 16
Check1 = 1
Combo2.ListIndex = 2
Case "Impossible to finish"
Text2 = 18
Text3 = 19
Text4 = 60
Text5 = 60
Text6 = 20
Check1 = 1
Combo2.ListIndex = 3
End Select
End Sub
Greetings - Jacek
|
|
|
|
|
oh fat cannon!
Yes, this confirms my oppinion. VB6 is the language with the most chaotic code i have ever seen. It's really a language for small short-life stuff.
For those who never where in that situation:
Imagine if you have a project with code like this in this language, but with 100000 source code lines...
|
|
|
|
|
Umm ... seems to me that the major coding horror of the OP's snippet is not that it's written in VB6, but that none of the variables are given meaningful names, there's no structure, etc.
The same horror could just as easily have been written in C#, etc., and the only thing you'd see differently is {} instead of THEN ... ELSE ... ENDIF, a few () scattered around, and '||' instead of 'OR', etc.
Not that I'd go out of my way to find a VB (6, .Net or other) job, of course.
|
|
|
|
|
Chris Trelawny-Ross wrote: find a VB (6, .Net or other) job,
Some times they find you.
|
|
|
|
|
I'm sorry if I hurt you.
Greetings - Jacek
|
|
|
|
|
Not hurt in the slightest. No apology needed.
|
|
|
|
|
Bigdeak wrote: Yes, this confirms my oppinion. VB6 is the language with the most chaotic code i have ever seen. It's really a language for small short-life stuff.
For those who never where in that situation:
Imagine if you have a project with code like this in this language, but with 100000 source code lines...
VB6 isn't perfect, but it didn't come fitted with a gun that pops out of the screen that forces you to write crap code.
Today, the most chaotic code I see is in VB/ASP.Net apps. And most of it knocks anything I ever saw in VB6 out of the ballpark.
And yet with both VB6 and VB.Net you can write beautiful elegant code.
So, why is there so much crap code out there?
Well...you're right. It is VB's fault.
VB made it possible for non programmers to program. Which means it made it possible for bad programmers to program.
The fact is, you see so much bad code in VB and VB.Net precisely because they are both such incredibly well implemented development tools.
The language isn't the problem, it's the numpty between the keyboard and the chair (no offence to the OP).
You will always see the worst code in the development tools that most appeals to the masses.
And the same simple fact has always been true.
Good programmers write good code. Bad programmers write bad code.
Suggesting that the language has anything to do with it is like advising a Spanish poet to learn English because you can write better poems in English.
|
|
|
|
|
At least in English, the poems ryhme.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Doesn't improve spelling much though, eh?
|
|
|
|
|
As in Spanish also I love my language
|
|
|
|
|
1. Option Explicit Off
2. On Error Goto Label37
3.
With Object.Its.So.Nested
(...)
abc = .Some.Property
(...)
End With
4. Global myVar As String = "magic"
5. someInteger = CInt(int1/int2) (divide operator on two ints gives... a double ).
6. Non-zero based arrays -- a fantastic source of confusion
7. Propagating null value in nullable boolean logic -- three-state logic? uhm? I won't be suprised if the next VB version would have a fuzzy logic implemented.
Not a problem with a language? I don't think so...
Greetings - Jacek
|
|
|
|
|
Jacek Gajek wrote: 1. Option Explicit Off
Yes this is horrible, almost as bad as JavaScript doing exactly the same, but with (until ECMAScript5) no equivalent of Option Explicit On.
Jacek Gajek wrote: 2. On Error Goto Label37
Quite horrible, but to blame VB for a fault in BASIC since the year dot is a bit unfair.
3. With/End With - OK, this is truly a mistake.
4. I don't like globals either, but most languages, particularly of that era, support them.
5. someInteger = CInt(int1/int2) (divide operator on two ints gives... a double).
Actually - thats pretty correct. Last time I checked 1/2 in mathematics was 0.5, not 0 or 1.
Ideally, a language can distinguish integer division and floating-point division, maybe with different operators, but this doesn't seem too horrible to me.
6. Yes, a terrible decision, and Option Base 0 just made things worse, as code in different modules can have different bases. I don't mind base 0 or 1, consistency is really important.
7. Not sure what you're referring to here, but if you mean null-propagation where nulls occur in boolean expressions (where null is an allowable result), that's the only option. Check the literature on Relational DB's (Codd et al.) for the justification.
Actually, Codd proposes 4-state logic (Yes,No,Maybe and Inapplicable, Maybe and Applicable).
These are not really boolean logic though, but VB, with typed variables (As Boolean) behaves correctly AFAIK.
It's not a great language, but most languages have points that are plain bad (JavaScript springs to mind heavily). Programmer's should be able to avoid features that cause problems - that's what they're paid for.
I've seen plenty of bad Javascript too - for basically the same reasons as VB.
Maybe we should just ban high-level languages
|
|
|
|
|
Rob,
You should consider more two VB features:
8. Automatic type conversions like:
Dim a As Integer = "1"
9. Not assigment or type checking at compile type:
Dim c As Object
Select Case c
Case 1
Case "horror"
Case Color.Green
End Select
This code generates a warning for use of c before its assignment, a incredible error, because it will never run. And it happens in modern VB.Net versions.
---
We could assume that you like VB and we could accept it. Every programmer have your "perfect" language and consider it best as no one other.
I know VB since version 5.0 and even today I use this language in a lot of legacy projects, but never in a new project.
I know a lot of other languages (C, C++, C#, Python, Perl, PHP, Javascript, Bash, Java, Delphi) and each time I will start a new project, I never consider VB, because its problems.
Fact is Basic and VB are extremely easy to start programming but they "easiness" are really complicated for the real programmer. A real programmer should be able to run a program and it need to be deterministic. Same input, same output.
Some time a go, a friend mine was asking why a simple sum operation became wrong. She was using ASP 3.0, which uses VBScript, and 1 + 1 are equal to 11. As I saw that, I told her, perfect normal, what was you expecting? I told her simple to type her variables Dim a As Integer = 1 , problem solved.
As me, and probably you, use VB along time both of us know that its evolution is really impressive. In version 5 and 6 its is a really poor in resource for type checking and compile time checking. Today it is more impressive, today 1 + 1 is really 2.
The easiness of VB 1, 2, 3, 4, 5 and we can consider version 6 to create and deploy windows applications are amazing, because your RAD and "good" (for the time) IDE.
Even with creation of Delphi, VB had evangelized his people.
But again, today, we can consider VB a good choice in real big and important projects. Project which requires use of good patterns, use o interfaces, a lot of modules, etc. VB can't handle this.
But again, it's my opinion. I consider VB a easy language not a good one.
|
|
|
|
|
Sergio,
Fair points - actually, I have to use VB at work but would much prefer use C#, or even better a true OO language like Smalltalk, but there seems little call for that in this neck of the woods. I've used VB in one form or another intermittently since VB 1.0 - at that stage, even though primitive by todays standards, the IDE was mind-blowing, the first time I was able to draw a GUI, and add event-handling code so easily.
I agree re. auto type conversion - in a typed language that's horrible, although many modern languages seem to do this sort of stuff (particularly in the Scripting arena, and I'd guess VB's kind of midway between there and a typical statically-typed language). Like you I have experience with a wide range of languages (slightly different selection, but generally similar).
Many languages have these kinds of faults - JavaScript has a whole set of them, but it seems to get nothing like the volume of criticism directed at VB. C has a whole different set, that tend to lead to more catastrophic run-time errors. The basic fact remains that whatever language you use, you need to learn its strengths and, particularly, its weaknesses, so you can exploit one and avoid the other.
Regards,
Rob
|
|
|
|
|
|
Any language which contains code to deliberately hide errors and pretend they didn't happen should not be released into the wild. Particularly if innocent and impressionable children (read: students) can be contaminated by it.
"On Error Resume Next"
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Try with an empty catch does just the same. Does this statement apply to all these languages, including C# and Java?
|
|
|
|
|
No, it doesn't! Try with an empty catch would only work the same if you surrounded each and every single line of code with it's own, independent, try...empty catch block. Not even the laziest programmer on the planet would do that...
Having said that, it is possible a very thick student might. But he wouldn't get a passing grade for it.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
That's true. My point was that a swallowed exception leaves the program in an invalid state. Even if the magnitude is smaller, no language can protect us from bad practice.
|
|
|
|
|
I agree - but a language that has that designed in to make it easy?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: No, it doesn't! Try with an empty catch would only work the same if you surrounded each and every single line of code with it's own, independent, try...empty catch block. Not even the laziest programmer on the planet would do that...
All you need is a try with an empty catch above the top level code, e.g. in a Button Click event, and all lower level code is covered.
So...asking again...
Should every language that has a mechanism for swallowing exceptions be pulled from the market?
I don't use classic VB any more except where maintenance is needed and that is needed less and less.
I do use VB.Net although I prefer C#.
Both C# and Java have their share of "features" that could attract every bit as much criticism as the features that people obsess over with VB.
And yet, I rarely hear those languages called into question to the same extent.
There's something about that word 'Basic' that just brings out the religious zealots on both sides of the debate.
To me VB has always been a tool, like a Hammer. I might feel a little sentimental from time to time, like a carpenter would about his first hammer, but it's just a tool. It has good and bad.
It revolutionised Software Development and it deserves a bit more respect for that than it gets.
More importantly, while it included features that allowed bad programmers to create complex code, it also included enough features to allow good programmers to write good code.
Very few of the features that people are critical of were absolutely needed. Create and enforce a few coding standards and VB could be used quite well for even complex systems.
The most important point to remember is that right now, out there in the wild there is code written in C# and Java that is 100 times more complex and difficult to read and maintain than anything that was produced in VB.
As a profession we should have enough self respect and pride to realise that code quality is predominantly a function of the developer not the tool.
Prior to college my only experience of programming was Basic. On my induction day for college back in the 90's I asked one of hte students showing us around if they used Basic at all.
"Basic? That's a baby language. We use C or COBOL"
When I started college I started messing with VB2.0.
A few weeks later that same guy approached me and asked me if I could show him VB, he wanted to use it for one of his assignments.
When I started work I used VB3.0. After a year or two I got a new manager who wanted us to start building Prototypes using an early version of Visual C++/MFC. He had VB programmers, but wanted use to only use VC++ (even for prototyping).
I quit, because think what you like about languages, some tools are just better for some things, and if you let ideology lead you into making bad decisions then I don't want to work with you.
No more excuses people.
It's not the tools....that are to blame for 'bad' code.
At some point we as a profession have to accept that for perhaps 15 years now there have been exceptionally good high level languages that can be used to build good quality maintainable code.
Let's stop wondering about which languages have dodgy features and start asking why we as a profession still produce so many coding horrors.
-Rd
|
|
|
|
|
Richard A. Dalton wrote: All you need is a try with an empty catch above the top level code, e.g. in a Button Click event, and all lower level code is covered.
It's not the same: On Error Resume Next causes execution to continue from the statement after the one that cased the error. An empty catch block will continue from the statement following the catch.
On error resume next
x = 3
x = x / 0
x = x + 1 would give an x of 4
try
{
x = 3;
x = x / 0;
x = x + 1;
}
catch {} would give an x of 3.
To duplicate the VB:
try { x = 3; } catch{}
try { x = x / 0; } catch{}
try { x = x + 1; } catch{}
I could argue that empty catch blocks are bad, but they can be justified under some circumstances (if they are documented sufficiently)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|