Visual Studio WTF
-
-
@remi said in Visual Studio WTF:
WTF VS, are you drunk?
Meh. It's close enough, just revert the few lines it fucks up.
Unless this is a regularly occurring thing you'll want to do....
-
@Tsaukpaetra said in Visual Studio WTF:
Meh. It's close enough, just revert the few lines it fucks up.
Unless this is a regularly occurring thing you'll want to do....
It was just a one-off to find the code I needed to edit, so truly I did not really mind those lines. Even more so as, like I said, there also were a couple of false positives that were actually correct according to the regexp, so it's not like I could blindly trust the result of the regexp -- and even if I could, I wouldn't have and was actually looking at the code before changing it (I know, )
So it's not a big deal by itself.
But it's still a WTF that 1) VS can't properly do a regexp search (yes, regexps are hard, but it's not like it's a brand new thing, nor like there aren't tons of libraries to do that) and 2) that VS isn't even consistent between the search done by the search box in the current document (to highlight matches), and the search done by "Find All" (to list all occurrences).
I posted it as a , not asking for help (inb4:).
-
@remi said in Visual Studio WTF:
Anyway. After some fumbling around, I end up with my regexp,
"([^"]*_|)E(_[^"]*|)"
. A string ("..."
) that contains aE
that is either at the start/end of the string, or separated by_
.I bet you were matching newlines or other whitespace, because while RE matchers are usually constrained to single lines, there are cases which ignore that restriction such as an explicit newline
\n
or an inverted character set match. Try adding them into the excluded sets; in some dialects this would be"([^"\s]*_|)E(_[^"\s]*|)"
(\s
being 'any whitespace') but I'm not sure if that's true of the one you're working with.
-
@dkf I wouldn't be surprised that it's the case, yes (and I'm a bit too right now to try again, I've moved on to something else...).
But even then, the key part that boggles me is that my regexp can be cut into "something complicated", a
E
, "something complicated." So whatever happens, the matched portion must contain thatE
. I can't see how that's not possible (except ifE
by itself has a special meaning, which I've never seen and if so isn't in the doc).There is no
E
in either of the false positives that make me go . Which is why it immediately makes me go .Then the fact that highlighting/"Find All" don't behave in the same way is the (an?) other .
-
@remi said in Visual Studio WTF:
There is no
E
in either of the false positives that make me go . Which is why it immediately makes me go .It's probably the IDE getting confused by the matching of multiple lines. I expect the issue is that the authors of it assumed that, because they passed the "right" flags to the RE engine, they'd never get multiline matches, and so didn't handle what to do if it happens. I don't remember if PCRE even has a mode where it excludes newlines from inverted sets; it's a subtle case that most people forget about.
-
@dkf this could explain the
")";
match, as indeed in the previous lines there is aE
(which isn't by itself, but if the match is confused by something else, this could still be it). But I had another look at another of the false positives and I can't find aE
anywhere near. So if it's a multi-line match issue, it has to search quite far back (or ahead) to find it, and this only makes it even more confusing as there are many other places where there is aE
but no match.Anyway, maybe I could manage to debug the reason for the whole thing, but that doesn't make it less of a bug.
-
@remi É È Ê
-
@BernieTheBernie more like
-
Status: I forgot, variables can't start with numerals.
But then, what is
3D
mean?
-
-
@Gustav said in Visual Studio WTF:
@Tsaukpaetra double.
They even use exactly "3D" as an example.
I've been in PHP land so long I forgot you could denote types in liberals.
-
@Tsaukpaetra said in Visual Studio WTF:
I've been in PHP land
We're here for you whenever you need to express your feelings
-
@Tsaukpaetra said in Visual Studio WTF:
I've been in PHP land so long I forgot you could denote types in liberals.
Please keep politics in the Garage.
-
@Tsaukpaetra said in Visual Studio WTF:
@Gustav said in Visual Studio WTF:
@Tsaukpaetra double.
They even use exactly "3D" as an example.
I've been in PHP land so long I forgot you could denote types in liberals.
Our literals tend to cover writing
0x12
,0b0110
,0o777
(bonus0O7
is valid octal) and1_234_567
rather than type inference as the type will be int/float rather than anything else.
-
@Arantor said in Visual Studio WTF:
0O7
is valid octal
-
@Arantor said in Visual Studio WTF:
bonus
0O7
is valid octalShurely shome shourche of amushement, there?
-
@Tsaukpaetra said in Visual Studio WTF:
I've been in PHP land so long I forgot you could denote types
in liberals.There, fixed it for you. ((/obligatory critique of PHP))
@Arantor said in Visual Studio WTF:
(bonus
0O7
is valid octal)That's less than you think.
0x2a
and0x2A
and0X2a
and0X2A
are all perfectly cromulent hexadecimal representations of The Answer, so it would be strongly if0o52
was accepted and0O52
was not.
-
@Steve_The_Cynic said in Visual Studio WTF:
@Tsaukpaetra said in Visual Studio WTF:
I've been in PHP land so long I forgot you could denote types
in liberals.There, fixed it for you. ((/obligatory critique of PHP))
Welcome, time traveler!
-
@Tsaukpaetra Well, TIL. I read through the page, and I had a distinct impression of "cobbled together, so it works mostly with tricks and traps ready at every stage."
But thanks for the link.
-
@Steve_The_Cynic said in Visual Studio WTF:
distinct impression of "cobbled together, so it works mostly with tricks and traps ready at every stage."
That's just PHP in general.
-
-
@Steve_The_Cynic while in principle I agree with you, in practice I’d be worried about the visual confusion of 0 and capital O in a way the others bother me less.
As for PHP typing, they’re really trying to unfuck the language. They’ll be there a while but they’re perfectly happy to warn “yo, this shit you’re pulling, that’s going away in a future version” where future version is likely inside the next couple of years’ worth of releases.
-
@Arantor You're not wrong about 0O and 0o, butit is, sadly, way too late to change that.
-
@Tsaukpaetra said in Visual Studio WTF:
It says it throws a TypeError on mismatch. That's … useless. The point of type information in the language is to check it at compile-time (i.e. when the script is loaded, for all code that is parsed even if it is not executed).
-
@Bulb said in Visual Studio WTF:
It says it throws a TypeError on mismatch. That's … useless. The point of type information in the language is to check it at compile-time (i.e. when the script is loaded, for all code that is parsed even if it is not executed).
Yeah, but the compiler can't know what values will be thrown at the function at runtime.
-
@Bulb said in Visual Studio WTF:
@Tsaukpaetra said in Visual Studio WTF:
It says it throws a TypeError on mismatch. That's … useless. The point of type information in the language is to check it at compile-time (i.e. when the script is loaded, for all code that is parsed even if it is not executed).
It’s partially useless. PHP still has a long way to go with dealing with the amount of at-runtime stuff where no amount of compile-time checking will help you.
That said, there are a few static analysers creeping into peoples’ CI workflow to catch cases that can currently be inferred at “compile time” but to get to the point where you could meaningfully do so at compile time… is realistically years away at their current pace.
-
@Watson said in Visual Studio WTF:
@Bulb said in Visual Studio WTF:
It says it throws a TypeError on mismatch. That's … useless. The point of type information in the language is to check it at compile-time (i.e. when the script is loaded, for all code that is parsed even if it is not executed).
Yeah, but the compiler can't know what values will be thrown at the function at runtime.
Yet that's precisely what the typescript transpiler does on top of javascript, and the mypy wrapper on top of python. Of course it requires enough of the code to be annotated, but once the standard library is annotated, decent inference gets you quite far without many explicit annotations of your own.
And note that typescript does not (by default) bother inserting any runtime checks. If it can't tell the type statically because the code is not annotated/annotated as returning any, it will throw on the invalid member access anyway, so an explicit runtime check would just slow things down without much of a real benefit.
-
@Steve_The_Cynic said in Visual Studio WTF:
@Arantor You're not wrong about 0O and 0o, butit is, sadly, way too late to change that.
And it's already miles better than C's leading zero madness.
-
@Bulb no, it’s not. The TS build is really a full AOT compile step in a way PHP’s isn’t.
PHP’s include/require are evaluated at runtime. And can be completely dynamic - require($file) is completely legal.
This means what you are loading and passing in literally cannot be inferred at compile time because what you’re compiling isn’t knowable at what you’re calling compile time.
Compile time is “the moment the PHP file is invoked” and often won’t be until just before use with autoloading being the prevalent style. Add to that the amount of dynamic shit in the frameworks today and you’re building a right storm of “cannot properly typecheck except at runtime”
-
@ixvedeusi we inherited that too. It’s just 0o came in as a less awkward replacement.
-
@Arantor said in Visual Studio WTF:
require($file) is completely legal
-
@Applied-Mediocrity to be fair, this does make some sense in the PHP world.
Each request starts with a clean slate (originally with a fresh instance of the interpreter outright), loading the file requested by the user as the starting point. Then you load the bits you need fir that request and then you’re done.
It’s not like Node or similar where the entire application is in memory ahead of time.
You either have two choices, let Apache be the front edge route and pass directly to a PHP file to do the work (old school) or you define a front controller that will have to dynamically load and execute a file based on the parameters.
-
@Arantor Ok, I was just wary about including remote files.
To allow inclusion of remote files, the directive allow_url_include must be set to On in php.ini
But it is bad, in a security-oriented point of view ; and, so, it is generally disabled (I've never seen it enabled, actually)
You bet that someone somewhere in a large production system has turned it on.
-
@Applied-Mediocrity oh, I’m sure it’s been done but most (certainly every project I’ve ever seen) sanitise away what gets included at that level.
Though curious how we don’t equally get CDNs of third party code in the browser…
-
@Applied-Mediocrity said in Visual Studio WTF:
@Arantor said in Visual Studio WTF:
require($file) is completely legal
It's worth remembering that this is legal in the C/C++ preprocessor:
(somewhere)
#define FILE_TO_INCLUDE "somefile.h"
(or)
#define FILE_TO_INCLUDE <somefile.h>
(somewhere else)
#include FILE_TO_INCLUDE
But at least it's a compile-time thing, and therefore dependent on your build system rather than some arbitrary variable retrieved from who-knows-where.
-
@Applied-Mediocrity said in Visual Studio WTF:
@Arantor Ok, I was just wary about including remote files.
To allow inclusion of remote files, the directive allow_url_include must be set to On in php.ini
But it is bad, in a security-oriented point of view ; and, so, it is generally disabled (I've never seen it enabled, actually)
You bet that someone somewhere in a large production system has turned it on.
Even without that, I've seen frameworks pretty close to
include($_GET['file'])
. And if you then pass?file=/etc/passwd/
what happens is exactly what you wish wouldn't.
-
@Arantor said in Visual Studio WTF:
That said, there are a few static analysers creeping into peoples’ CI workflow to catch cases that can currently be inferred at “compile time” but to get to the point where you could meaningfully do so at compile time… is realistically years away at their current pace.
There's been a lot of work in general on the development of static analysis tools for many languages, and hence a lot of experience with dealing with complicated things like PHP and JS. They analysis tools miss things still, but they're a still a boon in the (common) cases where what you're doing is well-behaved and not redefining the whole world frequently.
-
@Bulb said in Visual Studio WTF:
the mypy wrapper on top of python
It's not a wrapper. It's an analysis tool. It gets quite a lot right, but some things are just very very difficult to figure out the types of. In part, this is because the type annotations for Numpy are incomplete (it looks like a war between the people who want fixed size arrays and the people who want at least one dimension to be flexible) and in part it is because some people slap any old shit together. I now hate dealing with complicated union types (especially when there's no useful intersection types).
-
@Arantor said in Visual Studio WTF:
And can be completely dynamic - require($file) is completely legal.
But is it common? If not, you do deeper analysis on the files where it isn't there (and warn where it is). That's how the static analysis tools work in other languages: by assuming that the code is non-evil and howling if the assumption proves invalid. That does what most people actually want most of the time.
-
@dkf Require based on a variable? Yes. Virtually every modern PHP application does this because, at the bottom of it all, is Composer, as our package manager.
And one of the things it does is autoloading - which means it will at some point enter a function whose task is “this class does not exist, given a class with this name, can you identify how to load it for me please”
Which can very easily turn into mapping namespaces (
\NS1\NS2\Class
) to something in the file system (NS1/NS2/Class.php
) with a 1:1 mapping.Now, Composer does try to map all the possible classes it can find into an array but it will do a dynamic fallback anyway to map class to file system.
Which means you’re doing a require with a non constant. And with shenanigans that get pulled due to lack of runtime mixins, you get people doing all kinds of weird stuff with concrete classes extending not-existing proxy class names which are aliased at runtime to build a chain of single inheritance to sidestep the lack of multi inheritance.
-
@Arantor said in Visual Studio WTF:
And with shenanigans that get pulled due to lack of runtime mixins, you get people doing all kinds of weird stuff with concrete classes extending not-existing proxy class names which are aliased at runtime to build a chain of single inheritance to sidestep the lack of multi inheritance.
Hard OOP together with deep PHP. Oh joy!
-
-
@dkf PHP is not OOP preprocessor? No, doesn't fit. Page fault at... rebooting.... please wait... ah, PHOOP! Got it now
-
-
@Gustav sure, I just object to the similarity angle.
Mind you there’s only one reason I have to touch octal in PHP and fortunately it’s infrequently enough that I don’t mind…
-
@dkf said in Visual Studio WTF:
@Applied-Mediocrity said in Visual Studio WTF:
Hard OOP together with deep PHP. Oh joy!
PHOOP.
Sounds like you need some Pooph.
-
@PleegWat said in Visual Studio WTF:
Even without that, I've seen frameworks pretty close to include($_GET['file']). And if you then pass ?file=/etc/passwd/ what happens is exactly what you wish wouldn't.
Why does your webserver process can read the /etc/passwd file?
-
@dkf said in Visual Studio WTF:
@Bulb said in Visual Studio WTF:
the mypy wrapper on top of python
It's not a wrapper. It's an analysis tool. It gets quite a lot right, but some things are just very very difficult to figure out the types of. In part, this is because the type annotations for Numpy are incomplete (it looks like a war between the people who want fixed size arrays and the people who want at least one dimension to be flexible) and in part it is because some people slap any old shit together. I now hate dealing with complicated union types (especially when there's no useful intersection types).
How useful is it?
I've only read very little about it and since it's all so optional it seemed kinda useless, but I've never tried. I like static checking, but it also kind of feels like defeating the purpose of writing in something dynamic to begin with?
-
@Arantor said in Visual Studio WTF:
there’s only one reason
I haveto touch octalin PHPSetting Unix/Linux file permissions. Other than that, octal can die with the 1970s.