Observed today
-
// Doing it this way because we can't redeclare a defined constant later
WELL FUCKING DUH.
-
Some languages base it on scope...
const int x = 1; { const int x = 2; { const int x = 3; { const int x = 4; { //...
-
This is PHP which is just really immutable variables declaring; declared at runtime (and can be declared to be any scalar value, even calculating a value from a function)
-
This is PHP which is just really immutable variables declaring; declared at runtime
I'm having a hard time parsing this sentence...?
-
They're not real constants. Constants in real languages are fucking constant as in the value is hardwired through the assembly, and thus must be known at compile time.
In PHP, they don't exist until declared and can be declared at runtime, to any scalar expression. Once declared, they are immutable.
-
I am being a tutor for a programming 101 course on my university right now.
On the recent assignment the students were asked why a certain variable was declared constant.
One of the students wrote
It is declared constant because somebody wrote const in front of the variable name. There is no specific reason.
So... I was about as impressed with that answer as you were with that comment...
Filed Under: At least that course is not about PHP
-
PHP uses
define('CONSTANT_NAME', 'constant value');
half the time.
-
C has you covered with some
#define CONSTANT_NAME "constant value"
- macro nonsense if I remember correctly.... though I am glad the students don't know thatFiled Under: #define true false
-
Yeah but in C, that shit is compiled and the value won't change during runtime.
You can literally do:
define('CONST_TRUE', mt_rand(0, 1));
in PHP and get CONST_TRUE be true approx 50% of the time.
-
retardery thy name is PHP
-
There are only 3,741 other gotchas to learn.
-
Yeah but in C, that shit is compiled and the value won't change during runtime.
I thought PHP just compiled everytime a script was called?
What happens to your sample code if you have one of the extensions running that precompile PHP instead?
Filed Under: Science
Addendum: Wait, are you saying that everytime the constant is called in the script the value can change?!
Addendum Addendum: So, if thats what you are saying... can you overload true with your randomizer?
-
Wait, are you saying that everytime the constant is called in the script the value can change?!
Nope, you're thinking of Ruby.
-
Nope, you're thinking of Ruby
I would never think of Ruby!
Discourse is programmed in Ruby so I take offense in that!Filed Under: microagressed
-
It's not actually compiled. I'd say it's interpreted but 'fed into a blender and mangled until you get something out' is probably more accurate. It at least explains WordPress.
I'm saying the constant won't be constant until it's declared, and then it's constant until the end of the script - right up until the next time you run it.
-
I'm saying the constant won't be constant until it's declared, and then it's constant until the end of the script - right up until the next time you run it.
Aww, I was already starting my local xampp to test
<?php define("true",mt_rand(0,1)); $boxOpened = false; $catStatus = undefined; while(true){ $cat_status = alive echo "still alive \n\r"; if($boxOpened){ break; } } if(!$boxOpened) {$catStatus = dead; } $catStatus_real = $catStatus; echo $catStatus_real; ?>
Filed Under: I still don't know how to use Syntax highlighting in Discourse....
Addendum: I just realized that all ifs would be random in this code.... that would be soooo sweet!
-
I still don't know how to use Syntax highlighting in Discourse....
<?php define("true",mt_rand(0,1)); $boxOpened = false; $catStatus = undefined; while(true){ $cat_status = alive echo "still alive \n\r"; if($boxOpened){ break; } } if(!$boxOpened) {$catStatus = dead; } $catStatus_real = $catStatus; echo $catStatus_real; ?>
-
Wow... that worked... So it's 3 ` instead of 4?
This is SO DISCO(URSE)VERABLE!Filed Under: Thanks... I'll probably forget it next time I need it, though
-
// Doing it this way because we can't redeclare a defined constant later
Functional programmer meets real world.
-
In some respects this is a good thing it means I can calculate or otherwise determine and "environmental" or "configuration" value and define it as a CONSTANT (which I can use as a sort of "superglobal") in the Core Code. I don't have to worry about persistence because there is no persistence in PHP (joke). I.e. it only lasts as long as the webrequest exists even in OOP Stuff. With respect to OOP Stuff, only those Classes I choose, get put into session for use on another webrequest.
-
So it's 3 ` instead of 4?
This is SO DISCO(URSE)VERABLE!That's how Markdown works. Even GitHub works this way.
-
-
-
In PHP, they don't exist until declared
Actually, they do.
echo BUTTS; // prints "BUTTS" to the standard output define(BUTTS, Hello); echo BUTTS; // prints "Hello" to the standard output define(BUTTS, "BUTTS"); echo Hello; // prints "BUTTS" to the standard output
-
No, they don't. Your first line would normally issue a warning (though off hand not sure if
E_NOTICE
orE_WARNING
about an undeclared constant and it buttumes you want the same value as a string literal.
-
@Arantor said:
// Doing it this way because we can't redeclare a defined constant later
Functional programmer meets real world.The comment was written by someone who only knows PHP, HTML, CSS, JavaScript, SQL...
-
-
They're not real constants. Constants in real languages are fucking constant as in the value is hardwired through the assembly, and thus must be known at compile time.
Same in C++:
const
just means the variable cannot be changed once it's defined. You can still doconst int TRUE = rand() % 2;
and the value will be different for each execution. You can even take its address, or cast away the 'constness' so you can change the value (though with the above definition that would lead into nasal demons territory).Of course you can use a
#define
instead, but that's not even really a constant, that's just an glorified search / replace. Real compile-time constants weren't a thing in C++ until the introduction ofconstexpr
in C++11.AFAIK in C the situation is more or less the same (except no
constexpr
).
-
This post is deleted!
-
-
-
Stop using QWERTZ with dead keys!
Meh, I can't even complain about that... I made the 4 ` by creating 8 and moving 4 characters to the left.
That's how Markdown works. Even GitHub works this way.
Just because Markdown is shit doesn't mean stuff needs to be hard as shit to discover...
So, what is 4` for. Whats the difference between 1 ` and 2 ` (besides the amount of ` obviously?!)Markdown is a mess and you know it! Don't defend it by saying "big website X uses it"
Filed Under: </blakeyrant>
-
2/10 needs more FOSStards bashing.
-
There are only 3,741 other gotchas to learn.
3,741 other gotchas to learn, 3,741 gotchas to learn
Take one out, knock the version number about
3,954 gotchas to learn
-
You can literally do:
define('CONST_TRUE', mt_rand(0, 1));
in PHP and get CONST_TRUE be true approx 50% of the time.
-
Whats the difference between 1 ` and 2 `
Using `` lets you embed ` in your inline code, for example if you want to say "rm `find -amin +525600`
removes files that haven't been accessed in a year or more."```` isn't a thing.
-
-
@TwelveBaud said:
```` isn't a thing.
````
is most definitely a thing.It's the start of a code block with a hint that the language is `.
-
@TwelveBaud said:
```` isn't a thing.
````
is most definitely a thing.It is four things (specifically, backticks)
-
@Kuro Markdown is used in so many sites I use that I never forget these things. I could make your same argument with bbcode and its obscure tag names.
-
-
[quote=author]
has worked on every BBCode forum I have ever used. Not that that's obvious to new members.[quote=ben_lubar]test[/quote]
-
The old TDWTF forums used
[quote user="author"]
-
Yeah but in C, that shit is compiled and the value won't change during runtime.
You can literally do:
define('CONST_TRUE', mt_rand(0, 1));
in PHP and get CONST_TRUE be true approx 50% of the time.To expand on @ixvedeusi:
#define CONSTANT_NAME (rand() % 2)
"rm
find -amin +525600
removes files that haven't been accessed in a year or more."Assuming there aren't any funky filenames in that set, in which case it may remove some files that haven't been accessed in a year or more, as well as possibly some other files, and maybe none of the files it was supposed to.
-
The old TDWTF forums used
[quote user="author"]
…and sometimes it even worked. Still doesn't mean it's bbcode, though, even if it was "inspired" by it. In the same way that CS wasn't a viable forum system, but it might have been inspired by one.Filed under: Discourse, of course, is the opposite of inspired