Literally wrong
-
Dim doExchangeEntry As Integer = "0" Dim outOfOffice As Integer = "0"
Best thing about it? Right after that is a For-loop with the following near the beginning:
doExchangeEntry = 0 outOfOffice = 0
And those things are actually supposed to be truthy or falsey (in fact, they get implicitly casted to booleans later on) so ... WHY THE FUCK ARE THEY NOT BOOLEANS?
-
Someone got brainwashed by Oracle?
-
Alec Guinness' voice: Those aren't the data types you're looking for.
-
Are they casting string "0" to int 0, then use it as a bool?
-
Are they casting string "0" to int 0, then setting it to int 0 manually, then
useusing it as a bool?
Yes.
Although, each int might be changed to 1 if a corresponding property in the current object of the for-loop is true.
-
-
Maybe it was someone coming from JavaScript / PHP / similar background?
Doesn't excuse them but at least it offers some explanation of the mindset.
-
Dim outOfOffice As Integer = "0"
What kind of type system does VB has that allows this? In any static type language this would make the compiler slap you in the face.
I assume this is VB because it's the only PL language so stupid to use Dim to declare variables... What does Dim even means? Dim-ension?
-
What does Dim even means? Dim-ension?
Something like that.IIRC, VB allows you to assign a string to an integer because the compiler inserts an implicit conversion to integer.
-
VB.NET without Option Strict, yup!
-
So what does
Dim hehee As Integer = "haha!"
do? Parse error in runtime?
-
InvalidCastException.
-
Dim-ension?
It's an awkward bit of legacy. Originally, back in non-Visual Basic days, you used DIM to declare arrays, and variables didn't need declaration. In that case, DIM made sense, since you were specifying dimensions of the array.
Then they decided to actually get themselves a (slightly more) sensible type system, and for some reason reused the keyword.
-
What kind of type system does VB has that allows this? In any static type language this would make the compiler slap you in the face.
Welcome to the world of loosely typed languages. They help you...even when the help is wrong.
I mean, guess what happens when you do that with a non-numeric string.
So what does [this] do?
Dim hehee As Integer = "haha!"Run time error, of course.
-
Welcome to the world of loosely typed languages. They help you...even when the help is wrong.
WTB a way to pass browser JavaScript interpreters a
--stop-helping
parameter.
-
InvalidCastException.
Run time error, of course.
Goodie! Runtime errors are ALWAYS better than compile time ones!
-
Goodie! Runtime errors are ALWAYS better than compile time ones!
Darn straight, if you're into production failures.
-
Darn straight, if you're into production failures.
-
Works really well with the
http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-32-02-metablogapi/8054.image_5F00_thumb_5F00_35C6E986.png
mentality
-
HAHAHA
Wait, I 'd you until I refreshed. Bleh.
-
Blame MicroSoft for making
Option Strict
DISABLED BY FUCKING DEFAULT.If I were to enable it now, I'd probably have to rewrite almost the entire backend.
Not that it would matter much - our inheritance trees have issues and even in the C# components, type safety is belgiumed (Object type).
-
Unless this product was originally ported from VB6, I think the real WTF here is using VB.NET instead of C# in the first place.
-
Like any true practitioner of the art of the , I know not to celebrate until the five minute Server Cootie graceperiod has passed and a hard refresh has occurred.
:cupcake:
-
I fully agree. Our team will switch to C# for future projects.
-
There are only two things I can think of that VB can boast as better than C#:
- With blocks
- XML Literals
In all the time I've worked with C#, the total number of times I've wished for those features is… zero.
-
It’s been a long time since I used VB, but my memory is that trying to assign a string to a variable specifically declared to be an integer (as opposed to a variant) would cause an error. Am I remembering wrong, or did they change it after VB6?
-
trying to assign a string to a variable specifically declared to be an integer (as opposed to a variant) would cause an error
A runtime error, yes. Not a compile error.
Only errors at runtime, same as VB.NET.
-
I'd actually forgotten
With
blocks even existed.Thanks for making me remember.
(For some reason, this reminded me of C++'s constructor initialization lists, which in turn made me think of GCC kicking and screaming if you had
-Wall
set and the constructor initialization list had items in a different order than they appeared in the .h file)
-
With blocks
Is it this?
Dim theCustomer As New Customer With theCustomer .Name = "Abc" .URL = "http://www.microsoft.com/" .City = "Redmond" .Print(.[|Name|]) End With With theCustomer.Comments .Add("First comment.") .Add("Second comment.") End With
Please enlighten me, why is this bad? it looks kind of like c# initializers
-
You can't call methods in C# initialisers though
-
call methods in C# initialisers though
But one can nest them to achieve essentially the same effect , right?
-
VB.NET also has that style of initializer (also handled via the
With
keyword, but a different context).
-
Not really; you can only reference properties in C# initialisers
-
only reference properties
And they can be any type and lists etc, so you could nest them. (i just tested);
-
Please enlighten me, why is this bad? it looks kind of like c# initializers
Because it made me actually think about coding in VB.NET.
Also, it reminded me of C++ initializers and GCC's totally useless warnings about them.
-
@RaceProUK said:
only reference properties
And they can be any type and lists etc, so you could nest them. (i just tested);
Because those lists and stuff are accessed by properties; that doesn't go against the fact you can't call methods (of the object you're initialising)
-
-
There are only two things I can think of that VB can boast as better than C#:
With blocks
XML LiteralsBetter event handling support too.
-
The only advantage I see VB has is the
RaiseEvent
keyword; equally, I see no reason not to add that to C#
-
I think language-integrated XML traversal should be added to C#, but I also think that there are higher priorities first. So I'll stick to VB.NET for RSS/XSL/XML gumbo code.
-
I don't work with XML often enough for it to be an issue; it's usually hidden behind serialisers. And LINQ to XML is enough for the few times I have to manipulate XML directly.
-
You can't call methods in C# initialisers though
Dafuq?
Sure you can, if you write it in the form:
var poop = new Poop() { Color = TurdColor.MakeBrown(), Consistency = OMG( disease.diarrhea ), }
-
And later I corrected myself and added the qualifier that you can't call methods on the object/collection you're initialising within the initialiser
-
Well herp derp, how could that possibly work? NEWS FLASH: you can't call methods on an object that doesn't yet exist! Stop the presses!
-
Apart from the minor technical detail that the initialiser runs after the constructor