Visual Basic for Quantum Computers
-
@arantor what tickles my funny bone is:
why does "string == int" convert both sides of the equation to int instead of string?
-
@vault_dweller I've never quite understood the logic, but the official documentation says: "If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically."
I'm assuming this is because it makes the assumption that if you're comparing a string with a number, you probably want a numeric comparison, which given how much crap comes in stringly typed form.
-
@vault_dweller said in Visual Basic for Quantum Computers:
why does "string == int" convert both sides of the equation to int instead of string?
I come up against this occasionally in SQL. I try to write my code with the correct data types so I never rely on implicit conversion (and dates are always given an explicit format, I never expect to know how to parse the default format); but my colleagues are not always so careful, leading to cases where a process that has worked up until now fails with the "invalid number" error, because someone was checking whether the first character of the phone number string was 1 or 4 to work out how to format it, and then some user put non-numeric text in the phone number field. I modified the query to check instead for the first character being '1' or '4'.
-
@arantor said in Visual Basic for Quantum Computers:
@maciejasjmj it's not a necessity per se, more a logical convenience for people who don't understand what this means.
Imagine: page.php?something=1
if ($_GET['something'] == 1) { // do something }
A beginner would do this and then be confused when it didn't work as expected because it wouldn't occur to them to write it:
if ($_GET['something'] == '1') { // do something }
which would occur to us, but we're not the people PHP was originally aimed at.
That and the fact PHP doesn't have any kind of model about the data it's working with, so everything it gets is a string (or possibly an array if you do file.php?thing[]=1&thing[]=2)
https://golang.org/pkg/net/url/#Values
.
In this case,$_GET["something"]
would be equivalent to the C++ typestd::vector<std::string>
, so comparing it to1
or to"1"
would give you a compile-time error. Valid code examples include:if ($_GET->Get("something") == "1") { // do something }
if (parseInt($_GET->Get("something"), 10) == 1) { // do something }
shell_exec("/usr/bin/actual_code_written_in_real_sensible_language_and_compiled"); die();
-
@scarlet_manuka said in Visual Basic for Quantum Computers:
@vault_dweller said in Visual Basic for Quantum Computers:
why does "string == int" convert both sides of the equation to int instead of string?
I come up against this occasionally in SQL. I try to write my code with the correct data types so I never rely on implicit conversion (and dates are always given an explicit format, I never expect to know how to parse the default format); but my colleagues are not always so careful, leading to cases where a process that has worked up until now fails with the "invalid number" error, because someone was checking whether the first character of the phone number string was 1 or 4 to work out how to format it, and then some user put non-numeric text in the phone number field. I modified the query to check instead for the first character being '1' or '4'.
Phone numbers are NOT integers. They are arbitrary strings of a specific set of characters. You can't do anything meaningful on them using arithmetic operators.
-
@ben_lubar said in Visual Basic for Quantum Computers:
You can't do anything meaningful on them using arithmetic operators.
Don't be silly. You can always multiply them by zip codes!
-
@arantor said in Visual Basic for Quantum Computers:
`$_POST[...] == 1
it didn't work as expectedCompilationError: operator == is not defined between types 'string' and 'int'
-
@bb36e I'm hoping one day PHP will get there.
-
@arantor I mean hell it took until 7 for scalar type hints, I wouldn't be too optimistic
Even then, it's only runtime errors
But seriously rasmus, how the fuck did you think it was a good idea to make references to undefined variables not crash the program
-
@arantor said in Visual Basic for Quantum Computers:
'123abc' == 123 -> true
The problem is that
'123abc'
is being converted to123
at all.I don't know if the protocol for MySQL itself actually returns data type alongside the data it's sending back
It's a property of each of the columns in the result set, returned as part of the result set metadata.
-
@bb36e because he wanted to make it easier for beginners.
-
@dkf I didn't realise it came back as part of the metadata, I half assumed it didn't but honestly I couldn't be arsed to look at what actually came back from the server.
-
@arantor said in Visual Basic for Quantum Computers:
I didn't realise it came back as part of the metadata
I tried to find out what the actual return format was in order to confirm this (the bits I've seen were higher level things, so who knows how many layers of wrappers are making things work right) but the low-level documentation is terrible at actually saying what is going on and how it fits together.
-
@arantor said in Visual Basic for Quantum Computers:
@bb36e because he wanted to make it easier for beginners.
That's retarded. '123' converting to 123 I can accept, if I also accept that I will never use this language for anything ever. But '123abc'? What in the fuck?
-
@pie_flavor because it starts with a number therefore can be coerced to a number. I didn't say it was clever, merely that it existed. Under a philosophy of 'keeping going until we can't' because that's somehow beginner-friendly, this is an understandable if wholly misguided principle.
-
@pie_flavor said in Visual Basic for Quantum Computers:
'123' converting to 123 I can accept, if I also accept that I will never use this language for anything ever.
It induces quite a different type system to what you're used to.
-
@dkf said in Visual Basic for Quantum Computers:
@pie_flavor said in Visual Basic for Quantum Computers:
'123' converting to 123 I can accept, if I also accept that I will never use this language for anything ever.
It induces quite a different type system to what you're used to.
As in, no type system at all?
-
@pie_flavor said in Visual Basic for Quantum Computers:
@dkf said in Visual Basic for Quantum Computers:
@pie_flavor said in Visual Basic for Quantum Computers:
'123' converting to 123 I can accept, if I also accept that I will never use this language for anything ever.
It induces quite a different type system to what you're used to.
As in, no type system at all?
See:
Variant
.
-
@pie_flavor said in Visual Basic for Quantum Computers:
As in, no type system at all?
No, it has a type system. It is fully aware of int, float, string, array, and different types of objects including inherited ones.
The problem is that it is happier to juggle types on the fly than might be desirable, sometimes with annoying consequences. Comparisons between types is one of the more obvious cases but there is a more insidious one that can totally bite you: arrays.
More specifically, array keys. On the one hand you have numeric indexed arrays. You know, actual arrays. And then you have hashmaps which can have string identifiers as their keys. Or as PHP calls them, arrays.
Perfectly cromulent PHP:
$array = [ 0 => 'Zero index', 1 => 'First index', 'string_key' => 'This item has a string key.', ];
And you access them with the same syntax, $array[0], $array[1] and $array['string_key'].
Which can really bite you if you use a variable to do this and the variable contains something that looks like a number because then it'll be used as a numeric key! (No, not 123abc, that's not numeric looking, but 1234567 certainly does.)
Usually it's not tragic because you're probably pulling this out of a database and using the id column as the array index so the conversion doesn't hurt you. But under other circumstances this can be... problematic.
-
@arantor said in Visual Basic for Quantum Computers:
@bb36e I'm hoping one day PHP will get there.
==_real_equals
-
@boomzilla mysql_real_escape_string doesn't exist any more in the language.
-
@arantor like that's going to stop the jokes.
Like this one:
Oh, has it been replaced with
mysql_escape_string_for_real_this_time_we_mean_it
?
-
@jaloopa it's been replaced with mysqli_escape_string. Though you're really meant to use prepared statements anyway these days.
-
@arantor said in Visual Basic for Quantum Computers:
No, not 123abc, that's not numeric looking, but 1234567 certainly does.
So sometimes it's numeric looking and sometimes not?
-
@mrl yes :(
If you're doing array stuff, a string composed entirely of numeric characters without leading zeroes would be a numeric array index, otherwise type juggle.
https://3v4l.org/kcGM2 for an example.
-
@arantor said in Visual Basic for Quantum Computers:
@mrl yes :(
If you're doing array stuff, a string composed entirely of numeric characters without leading zeroes would be a numeric array index, otherwise type juggle.
for an example.And with leading zeros?
-
@mrl With leading zeroes, they're assuming to be strings like everything else. The literal case for 'this is going to be a numeric array index' is where the array index is specified as
^0|([1-9][0-9]*)$
.
-
@arantor said in Visual Basic for Quantum Computers:
@mrl With leading zeroes, they're assuming to be strings like everything else. The literal case for 'this is going to be a numeric array index' is where the array index is specified as
^0|([1-9][0-9]*)$
.But in normal comparisons '0123abc' == 123 -> true, correct?
-
@mrl in normal comparisons, yes, because it's cast to an int and not subject to some of the OTHER process that goes around.
'123abc' == 123
'0123abc' == 123
'0123abc' != 0123 as a literal because 0123 is interpreted as octal for fuck knows why reasons
-
@arantor said in Visual Basic for Quantum Computers:
because 0123 is interpreted as octal for fuck knows why reasons
Because that's how sane languages operate. Works the same in Java.
-
@pie_flavor that's sane? In an era where octal is largely irrelevant, it's sane to do that?
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor that's sane? In an era where octal is largely irrelevant, it's sane to do that?
It is used by some Java programs somewhere, so removing it would break things. It is useful to have a syntax for such a thing, since 'intended usage' is meaningless on an extremely-general-usage language like Java.
-
@pie_flavor I suppose Java is broader, but PHP has no excuse. There is precisely one situation I've ever had to use octal in PHP - with the chmod function, as 0666 is different to 666 for that.
-
@ben_lubar said in Visual Basic for Quantum Computers:
You can't do anything meaningful on them using arithmetic operators.
Nobody was trying to. The only operation we were doing on them was substr(phone_number, 1, 1).
The problem was comparing the resulting string to an integer constant instead of a string constant.
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor I suppose Java is broader, but PHP has no excuse. There is precisely one situation I've ever had to use octal in PHP - with the chmod function, as 0666 is different to 666 for that.
And there are precisely zero situations where you have had to begin a decimal number with a 0. We have a majority.
-
@pie_flavor said in Visual Basic for Quantum Computers:
And there are precisely zero situations where you have had to begin a decimal number with a 0
Exactly, so why the hell does PHP have it?
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor said in Visual Basic for Quantum Computers:
And there are precisely zero situations where you have had to begin a decimal number with a 0
Exactly, so why the hell does PHP have it?
You are not reading what I am saying.
You can think of one common usage of octal. There are probably more.
However, there is no purpose to putting a 0 in front of a regular decimal number, so the fact that doing so changes the meaning is irrelevant given that you shouldn't be doing so anyway.
-
@pie_flavor I can think of one common usage of octal in a web based language.
I accept that my earlier premise about it being generically obsolete was wrong, but that doesn't change it for a more specific environment. But, sure, beat me over the head with how wrong and stupid I am.
-
@arantor said in Visual Basic for Quantum Computers:
in a web based language.
PHP is a general-purpose scripting language. Its most common use simply happens to be webdev. I, for instance, have written a couple of plugins for a Minecraft server written in PHP.
-
@pie_flavor It is not a general purpose scripting language.
1995, the language is specifically introduced for making a website without resorting to using C. It is literally called Personal Home Page and comes built in with a primitive templating language. (v1.0)
2002, command line support is introduced in version 4.3.
2012, internal web server for development use, in version 5.4.
But sure, we can insist that a language that was literally web-only for the first 7 years of its life (and when it consolidated its power base as a language, as well as 90%+ of its real world use today) is in fact a general purpose scripting language.
Yes, you can do things in it that aren't web based. Doesn't make it general purpose just because you can do it.
I've written fucking desktop apps with GTK in it. That doesn't make it general purpose - it makes it web based but occasionally tries to do other things.
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor It is not a general purpose scripting language.
1995, the language is specifically introduced for making a website without resorting to using C. It is literally called Personal Home Page and comes built in with a primitive templating language. (v1.0)
2002, command line support is introduced in version 4.3.
2012, internal web server for development use, in version 5.4.
But sure, we can insist that a language that was literally web-only for the first 7 years of its life (and when it consolidated its power base as a language, as well as 90%+ of its real world use today) is in fact a general purpose scripting language.
Yes, you can do things in it that aren't web based. Doesn't make it general purpose just because you can do it.
I've written fucking desktop apps with GTK in it. That doesn't make it general purpose - it makes it web based but occasionally tries to do other things.
Even the onebox agrees with me.
-
@pie_flavor jesus fucking christ.
The first line: designed primarily for web development - agrees with what I said.
And just because it is used as a general-purpose programming language does not make it one.
Now I remember why I wanted to leave this fucking cesspool again.
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor jesus fucking christ.
The first line: designed primarily for web development - agrees with what I said.
And just because it is used as a general-purpose programming language does not make it one.
In your opinion, is sildenafil citrate better categorized a blood pressure medication, or an erectile dysfunction alleviator? What something is designed for is not necessarily what it is.
-
@pie_flavor PHP is still far closer to a web scripting language than a general purpose one. But because one time you didn't use it for that, that somehow invalidates the premise.
Fuck off.
-
@arantor said in Visual Basic for Quantum Computers:
@pie_flavor PHP is still far closer to a web scripting language than a general purpose one. But because one time you didn't use it for that, that somehow invalidates the premise.
Fuck off.
Does anyone use Ruby for anything other than Rails these days? Is Ruby a web language?
-
@pie_flavor said in Visual Basic for Quantum Computers:
As in, no type system at all?
No. The correct type system to induce is very much more WYSIWYG, and the underlying type algebra has interesting properties, e.g.,
0
is a floating point number and an integer and a bunch of other things all at the same time. It's really very different to what you're used to, but can still result in very good code being generated. (You end up with strings being the supertype of all other types, yet with the machine representation of a value being rather more sophisticated.)Or you can have what PHP does which… well… that's not what I'm talking about. OK? ;)
-
@pie_flavor said in Visual Basic for Quantum Computers:
Does anyone use Ruby for anything other than Rails these days?
Unfortunately, yes. I've seen it used as a general-purpose scripting language for automating some part of the process of compiling and/or simulating digital chip logic.
I forget exactly what partOh, my.... I remember now. Configuration files, written in YAML, embedded inside a Ruby script. Or the other way around. foo.yml.rb, or was it foo.rb.yml. One of them. Also, at another company, just an ordinary script — I forget what it did — something I'd have written in perl or python, somebody wrote in Ruby, because why not?
-
@bb36e said in Visual Basic for Quantum Computers:
But seriously rasmus, how the fuck did you think it was a good idea to make references to undefined variables not crash the program
@arantor said in Visual Basic for Quantum Computers:
@bb36e because he wanted to make it easier for beginners.
Easier to do the wrong thing? Easier to screw up and not realize it, so it's that much harder to ever progress beyond beginner level?
-
@masonwheeler said in Visual Basic for Quantum Computers:
Easier to do the wrong thing? Easier to screw up and not realize it, so it's that much harder to ever progress beyond beginner level?
Do something fairly reasonable instead of something that would frustrate the beginner and make them quit because nothing was working. I'm reminded of
ed
.Let's look at a typical novice's session with the mighty ed:
golem$ ed ? help ? ? ? quit ? exit ? bye ? hello? ? eat flaming death ? ^C ? ^C ? ^D ?
-