« first day (1434 days earlier)      last day (3529 days later) » 

4:02 PM
frankly, pure FP has a really big problem -- it fundamentally opposes actually doing stuff.
 
posted on September 19, 2014 by kbironneau

/* by studyuchebag */

 
sure, you can simulate side effects and such by returning a new world with the changes you want made...but even then, at some point, the "this is the current world" reference has to change.
 
user895378
@cHao Totally agree. The right approach (IMO) is mixing and matching FP concepts with OOP where it makes sense.
 
user895378
One can support and improve the other.
 
@AndreaFaulds What's the problem with just ?= ?
 
4:16 PM
@bwoebi being inconsistent
 
What NikiC said
 
Following that, what would be the problem with just ? for coalescing?
 
@DanLugg ambiguity
 
With?
 
@DanLugg being hard to distinguish from the ternary, maybe to the point of ambiguity
 
4:17 PM
Eh. Meh.
 
Think of a ? b ? c : d for example
 
@NikiC actually it's maybe confusing, but not ambiguous…
 
Yea, as are nested ternaries anyway.
 
as the operand needs to be a variable, there's just one way to resolve it.
 
a ? b ? c ? d : e : f : g
 
4:19 PM
@bwoebi the operand doesn't need to be a variable
 
^^ I'd hope not.
Is ?? going to be based on falsey or nully?
 
@NikiC I thought (I mean for the new operator)
 
a ?? b is isset(a) ? a : b for variables and a !== null ? a : b otherwise
 
@DanLugg I hope it'll be on undefined.
 
@DanLugg null, that's the whole point of a separate operator
 
4:20 PM
@NikiC oh, okay, then I missed something.
 
Why not !empty()?
 
@DanLugg because nobody wants that
 
lol
 
empty is stupid
 
agree.
 
4:21 PM
or rather, php is stupid and empty is stupid by transitivity
 
^^
 
lol
 
@NikiC the thing which sucks about empty, is that it checks for "0" too. (well, it's a boolean cast internally…) But it's called empty() and "0" is not an empty string :-/
 
@bwoebi yes
that's just the thing
 
if only we could go back in time...we could eliminate php's warts retroactively
 
4:25 PM
Isn't that an issue inherent to scalar casting though, and not just empty?
 
course, in the end, we'd probably just have a slightly beefed up Ruby.
 
@NikiC That really should be changed in the next major. I know it's a BC break, but I really never use it to check for "0"… dammit…
 
@DanLugg which is why all of us use === whenever possible
 
@NikiC Of course.
We should just deprecate ==
 
/me made an external object consistent with isset/empty the other day ... when I was finished, I felt ashamed ...
 
4:26 PM
@DanLugg We should rename it to ==(unsafe!!!)
 
@DanLugg it's okay if you just do an if ($var) check where you want to just check if it's something which could be falsy. but empty()…
 
i do wish i could just say if ($var) without triggering a notice :P
 
Fatal error: Equality comparison (T_IS_EQUAL) has been removed in ...
 
@DanLugg i will stop using PHP if that happens.
 
@DanLugg "Yea, as are nested ternaries anyway." Fixed.
 
4:29 PM
@cHao No you don't. That's a very, very stupid thing to say. Unless you are using register globals, in which case it's even more stupid.
 
@Danack I thought I messed that up, thanks :-)
 
@NikiC yes, i do. i have often considered turning notices off for that sole reason.
 
you are allowed to wish that if($_GET['var']) does not throw a notice, but silently allowing if($var) is an entirely different matter
 
@NikiC Really? $_GET is any different?
 
to me, it's the same thing.
 
4:32 PM
@cHao no. Notices are there to show you potential bugs...
 
There's a minor difference between missing user supplied data and your code being total and utter crap (which is what code is when you're using variables that don't exist).
 
like notices catch quick typos…
 
@bwoebi and if i know it might not exist, and i don't care, i shouldn't have to write extra code just to let PHP know that.
 
@NikiC I'd argue that the issue isn't user-supplied data, so much as it's the construct that data is contained within.
 
4:33 PM
the only problem is that undefined variables are just a notice. rather than an exception.
 
@NikiC How about if ($arr->isEmpty())? :D
 
the only problem is that too many people can't freaking type.
 
$_GET should then be an ArrayAccess with null returned from offsetGet on missing keys.
 
@NikiC you'd like an exception? ... yep. agree.
 
Hey guys...
wiki.php.net/rfc/integer_semantics#vote <-- look at that vote total
 
4:33 PM
@bwoebi or a compile time error, after we also get rid of varvars :D
 
something something cold dead hands
 
Dictionary::offsetGet throw on missing keys, SafeDictionary::offsetGet returns null on missing keys.
 
PHP is not C. stop trying to make it strict.
 
@NikiC so, you'd like even more shittier code like $varvar = &$GLOBALS[$var]; ?
 
@cHao Strict-er code is easier to test and rationalize.
 
4:36 PM
@bwoebi not sure how that's related to varvars. but yes, accessing globals should of course be as painful and ugly as possible :)
 
if you want strict, go use Java.
stop trying to fuck up PHP with your strictness.
 
lol if ($nonexistent) throwing isn't overly strict, it's bailing out when your code is borked.
 
@NikiC because that's how you'd do varvars in global scope.
 
@bwoebi yeah, but who does that?
 
People then will just write their shit in global scope, so that they can emulate varvars
 
4:37 PM
apart from codeigniter I mean
 
i use $$var. i like that i can do that.
 
Actually, varvars are legitimate, I think, but have really restricted use cases, just like extract() does.
 
@bwoebi I think varvars are okay in the form of local_var($var)
having a special syntax for them was a mistake
 
So a construct/function that reads the symbol from local scope?
 
is it really a special syntax? that's a parser issue
 
4:39 PM
That's not bad; $v = local($k)
 
@NikiC Not sure if I should agree, but I could live with both variants.
 
i've never tried $$$var, but if it doesn't work, php's parser is even crappier than i thought.
 
@DanLugg that's what python does
 
Neat. Not really a python user, so didn't know that.
 
or ${$var}
which should work already, afaik
 
4:42 PM
@DanLugg or rather, it's locals()[$k]
 
yeah, i just tried it. it does.
 
@NikiC Oh, it kicks back a dictionary or something?
 
and that's a good thing.
 
yup
 
4:43 PM
$x = []; for ($i = 0; $i < 10; $i++) { $x[$i] = $x[$i - 1] + 1; } is both valid PHP code and valid JavaScript :D
 
@cHao s/good/subjectively opined/
 
@DanLugg yes, in my opinion it's good -- and removing it would be bad.
 
@cHao don't fear, not gonna be removed ;)
 
...yet
 
variable variables are kinda dumb
 
4:44 PM
:D
 
But they're fun for templating
 
Yes, if you hate the person you're passing the templates off to
 
yes, I think templating is the one and only (potentially) legitimate use of varvars
 
foreach (['a', 'b', 'c'] as $var) if (!isset($$var)) $$var = null;
 
@AndreaFaulds Oh, you mean varvars through extract()?
 
4:46 PM
@DanLugg Yes.
@cHao use an array
 
one of my more common workarounds to the fact that PHP's so anal-retentive about variable names.
 
PHP is hardly anal-retentive about variable names
 
Ah. I don't like extract either; $this->property through __get is more sensible (IMO)
 
@cHao that's one of those cases for which you certainly don't want to use them
 
@AndreaFaulds i don't want an array. these are discrete things.
 
4:47 PM
@cHao can you provide broader context for that snippet?
 
i like extract too :P
 
@NikiC The silly JS code? There is none
I just like how JS having $ be legal in varnames means technically some PHP scripts are valid in JS too
 
@cHao Isn't $a = $b = $c = null easier to understand?
 
It's not a good idea, though
Except for code golf :D
 
Oh wait, you're initializing them.
 
4:48 PM
gtg eat bye
 
@DanLugg he could still do what you just said before conditionally defining them - it just doesn't make sense. Only context in which it could possibly make sense is register globals.
 
@DanLugg if you like overwriting stuff, sure
 
@cHao If you're ever looking for code-review, and somehow my name ends up on the list, please just cross it out.
@cHao $a = isset($a) ? $a : null
 
@DanLugg heh. my code isn't nearly as bad as you'd think.
@DanLugg and that is exactly what i hate having to do.
 
Why, because you have 8,000 variables? Then that's a problem.
 
4:51 PM
because code written entirely to tell PHP that i'm not making a mistake, is code i shouldn't have to write at all.
 
@cHao So, like rarely used, but essential things to not work in some obscure cases, just because there was a notice which wasn't logged…
 
@cHao again, what's the context here? if you're conditionally defining variables, why can't use initialize them beforehand?
 
@NikiC What about superglobals?
$_POST, $_GET
 
@SecondRikudo He is referring to plain variables
 
Why do I need 50 isset calls for my 50 fields form with all required fields?
 
4:54 PM
not to arrays
 
SSDD
I like JavaScript's way of using undefined, and then you can just
 
plain variables and array indexes are pretty much the same in my eyes.
 
but variable variables
 
var stuff.x = stuff.x || 'default value'
Simple and elegant.
@NikiC $$var is just as possible as $_POST[$var]
What's the difference?
 
i think of a function's variable namespace as just an array with shortcut syntax.
 
4:56 PM
@SecondRikudo $array = ["var" => "default", "var2" => "default2"] + $_GET; then you don't need isset().
 
@bwoebi That's not simple, nor elegant, nor does it work for required fields.
Why can't I if (!$_GET["poo"]) {?
 
I'd frankly prefer if:
24 mins ago, by Dan Lugg
$_GET should then be an ArrayAccess with null returned from offsetGet on missing keys.
 
@SecondRikudo because $_GET["poo"] might be "0" too… and what if 0 is a valid value?
 
Rather than making weird special cases for dereffing arrays, etc.
 
@DanLugg Yes, I think so too.
Personally, I want a Request object
Sure, I implement it in userland every time, but I really think that a request object is kind of a basic thing.
 
4:59 PM
I'd just prefer that PHP had a more appropriate abstraction over HTTP. $request->queryParam() is much preferable to $_GET imo
 
A "standard" Dictionary and SafeDictionary, where the former throws on missing, and the latter returns null
 
@cspray My point exactly.
 
@SecondRikudo Since PHP is supposed to be a web language I think a real HTTP abstraction is warranted
 
Is there an issue with just adding rdlowrey/Arya in your composer.json?
 
@SecondRikudo This is my biggest qualm, that so many of the quintessential uses-cases of PHP aren't covered by built-ins, and require disparate userland implementations.
 
4:59 PM
@bwoebi Yes
It's code I haven't written, and now it's part of my project.
And if there's a bug in it, I have a bug in my code, and I have no idea how to fix it.
It's a third party library, an extra dependency.
Not that I don't value rdlowrey's libraries (or any other library for that matter), but I think that, like @cspray said, PHP is a plugin language written on top of an HTTP server. Proper HTTP abstraction is warranted.
 
@cspray Not to mention a non-crippled DOM implementation
 
I don't think that anyone here disagrees that globals suck.
 
@SecondRikudo http is just a feature of PHP nowadays.
 
And yet the language insists on having the most basic usages as globals.
And even call them SUPER globals, as if that makes them better.
@bwoebi Uhhhh, no?
 
@SecondRikudo uuuuh, yes!
 
5:02 PM
I don't know of many web apps (or even sites, for that matter) that don't have forms or GET variables.
 
user895378
The problem is that PHP's http abstractions suck. HTTP is much better understood by far more developers today than it used to be.
 
user895378
First class http support is no longer a benefit to php.
 
user895378
It's a gimmick.
 
user895378
Especially considering our http abstractions are crap.
 
So what do you think is important for PHP?
 
user895378
5:03 PM
</opinion>
 
user895378
Being a good language :)
 
@rdlowrey Good luck with that.
Given how people are afraid to change how the integers work in a few edge cases in a major version
 
user895378
lol inoright
 
Right now it's at exactly 2/3 it seems
Are there more people who still need to vote?
 
5:06 PM
@PeeHaa WE'RE HAVING A SERIOUS DISCUSSION HERE GTFO WITH YOUR CRAP QUESTIONS
=P
 
:-D <3
 
@Leigh, default seems really unintuitive as a "do this if the loop was not entered" keyword... how about otherwise? Or anything else? I understand why else isn't sane to do...
 
@Charles I think else is the most intuitive choice.
Given that everyone knows it from the ifs.
 
@SecondRikudo I agree in principal but there are examples in the document that show where there can be ass-biting around one-liner conditionals and the alternate syntax.
 
php is too mature at this point to ever be a good language again. the best we can do is get rid of a couple of little warts
 
5:08 PM
@cHao s/again//
 
@cHao again?
damn you @Charles
 
@Charles Oh, I'm sorry, are we talking about implementing a cool and useful feature? Or about teaching idiots some sane code style?
 
@SecondRikudo Won't somebody think of the wordpress "developers"!?
 
yes, "again". :) it was good for what it was originally there for. then people decided to try to turn it into a real programming language.
 
5:11 PM
granted, it's come a long way, but it's grown a lot of hair in funny places too.
 
I actually use the one-liner syntax all the time. So there. Nya.
 
@cHao When it originally started, it used the function name's length as a hash function, and as a result we have this crappy naming scheme.
PHP was not a good language to begin with.
 
@SecondRikudo wait, what?
 
@cHao Lemme find that discussion, okay?
 
@SecondRikudo I have read that 6 times now and am still clueless what that sentence means :P
 
5:12 PM
@PeeHaa To cheaply lookup a function in an array, you want to hash it into an integer in that array.
You want your functions as equally distributed as possible across the array, for maximum performance
PHP used strlen as their hashing function.
 
huh?
 
and then Rasmus chose a crappy hash algo to do it
combine that with "C function names are good enough for anybody" and we get the standard library!
 
So to make sure it's equally distributed, and each character length has about the same amount of functions, we have crappy names like bin2hex and strtolower
 
@Charles And then he took those functions and rot13ed everyting right?
 
bin2hex() is not so bad.
 
5:14 PM
Enjoy
@Ja͢ck If you start with bin2hex go for str2lower as well
 
holyfuckeroly that is stupid
 
@PeeHaa And that, my friend, is PHP.
All the way back to the start.
 
Or bintohex() for that matter.
 
@Ja͢ck Personally, I think either bin_to_hex() or binToHex() are best.
 
Was bin2hex already in PHP-FI?
 
5:17 PM
ok screw this. Enough misery for one day. I'm going out to get beers
 
@PeeHaa Good plan.
 
@SecondRikudo Ah, but then there's dechex() :)
 
Make them all deprecated aliases and drop in NEXT_MAJOR+1 :-D
 
hehe
 
5:21 PM
@Ja͢ck My point exactly.
These functions weren't named with consistency in mind. They were named with how well they spread across lengths in mind.
 
Who would have thought we suffer for that decision 20 years later? :)
 
@Ja͢ck Really?
 
Really what?
 
Because you've never seen a proof of concept become production code?
You've never seen poor decisions made to save time or effort affect code for generations to come?
 
You've never heard of sarcasm?
 
5:25 PM
:P
@Ja͢ck That's not the only bad decision that was made.
 
heh
 
Try to find out how goto managed to become a thing in PHP.
 
ok, i guess i have to take back the "used to be good"
 
Pff, that's the least of our concerns.
 
Why don't we have namespace importing in PHP? Like use namespace Arya; and you have imported all the function/classes in the current ns? I know that we already had similar discussions, but why was it rejected?
 
5:28 PM
you mean like .... import Arya\*;? :)
 
or similar, yea.
 
@bwoebi Because autoloading?
 
@DanLugg the autoloader might be called twice?
 
@bwoebi Autoloader may not be able to resolve names.
use Foo\*;
use Bar\*;

new Qux(); // FQN is Foo\Qux, but it may need to try Bar\Qux
Although, I guess that's not too much a problem.
use Foo\*, Bar\*, Qux\*, Zip\*, Zap\* // possible with lots of lib deps
And each needs to be checked iteratively.
 
recipe for disaster? :)
 
5:34 PM
make it fun, have it evaluate as a regex
 
See, I like the idea that @LeviMorrison was talking about, some sort of native packaging support. Then, packages could define bootstrappers which pull their namespaces in.
 
use Foo\[a-z]*Facade;
 
lol
 
master broke on Darwin =(
 
@DanLugg What'd actually be the issue with it?
 
5:39 PM
@bwoebi Probably not much, come to think of it.
Performance? Nah. Ambiguity resolution? Maybe.
 
@DanLugg resolution order is the order in which you do the use stmts...
 
@AndreaFaulds Yes I would mind.
 
@bwoebi filesystem hit for scanning a directory, plus how do you tell what files are meant to hold classes, and which aren't.
 
@rdlowrey terribly... awesome? :D
 
user895378
@salathe exactly.
 
5:41 PM
@bwoebi I'd prefer exceptions on multiple definitions for the same FQN.
CALL ALL THE AUTOLOADERS!
 
exceptions would be fine. Just like Java fails too in that case.
 
@tereško huh.. yay
Hopefully, I'm leaving next week
since my visa is ready, it's a matter of rent now. And that's it. Well enough for me
 
5:58 PM
should i have to use a special function to open a simple text file in wordpress
i am using this code
if($wp_query->query_vars['blog_type']=="blogfa")
{

$blog_dir= get_post_meta($post->ID, 'blog_dir',true);
$path=bloginfo('stylesheet_directory')."/blog/".$blog_dir."/blogfa.txt";
echo $path;

$myfile = fopen($path, "r") or die("Unable to open file!");

// Output one line until end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
}
and i get this error
 
that's almost readfile().
 
http://localhost/wordpress/wp-content/themes/slidtheme/blog/0/blogfa.txt<br />
<b>Warning</b>: fopen(/blog/0/blogfa.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>C:\wamp\www\wordpress\wp-content\themes\slidtheme\Entire_page.php</b> on line <b>30</b><br />
Unable to open file!
 
The warning seems obvious.
 
i swear that i have the file in blog /0 directory
i even open the file by browser
 
How about using DIRECTORY_SEPARATOR instead of '/'.
 
6:00 PM
@Ja͢ck what u mean directory separator
about
 
No, I mean DIRECTORY_SEPARATOR.
Besides that, it seems that bloginfo('stylesheet_directory') is empty.
 
is helping people with wordpress ethically wrong ?
14
 
@JoeWatkins do u like to hang out me?
 
dunno, is helping a murderer move their sofa wrong?
 
@Jack yes
 
6:03 PM
damn
 
@Ja͢ck I think the better analogy would be "is helping a murderer sharpen their knife wrong?"
 
you know i echo $path variable it and copy the text to browser it's opened well
 
@DanLugg no, i think this will do just fine :)
 
:-P -- I've helped move many sofas; surely one of the people has killed someone.
 
reminds me of the odds of calling somebody at random who has just committed murder heh
 
6:07 PM
well sofa philosophy lol
 
@Ja͢ck I think the odds of calling someone who just sneezed are 1:40,000?
 
@DanLugg do u have phD in moving sofa :D
 
@Markberg No, I have a lack of regard for lower-back health.
 
@Markberg fopen(/blog/0/blogfa.txt) this is a filesystem path. You are looking for /blog/..yadda yadda at the root of your file system
 
@DanLugg Exactly! Reading the book :)
 
6:10 PM
@Ja͢ck lol, yea, murder is 1:1,000,000,000? (edit: was missing several 0's, thankfully)
We should spearhead an International-Call-A-Random-Number-And-Wish-The-Answerer-A-Good-Day Day
 
Yeah, based on a rate of 4 murders per 100,000.
 
that's 1 in 1 billion people are murdered or are murderers ?
 
same thing lol
nah, the latter.
so .. could be one guy killing 4 people so that the other 99,999 don't have to.
 
a friend of mine was charged with murder, found guilty of manslaughter ... got 11 years, just looked it up ...
 
nice of him to save us the trouble
 
11 years for manslaughter? guess it depends, was it self defence?
 
that was actually a response to Ja͢ck, your message just ninja'd it's way in before it
 
he was bullied by the lad he killed for years, countless times I had scared andrew away ...
he was on his own that night ... he panicked and got into his car, three big lads stood in the road to corner him and rather than get beat up, his drunk mind decided best to drive at them ...
 
fear makes people do weird things
=(
 
I don't get git blame
I just moved a large chunk of code to a new file. My expectation was that git blame -C would not blame that commit
However it still gets blamed even with git blame -w -M -C -C -C
 
6:21 PM
@derp what is your solution
 
@NikiC It knows what you did there.
 
or give me a reference
 
@NikiC It's an addition to -M, which says that it will blame both parts.
 
@derp are u a American
 
Wow.
 
6:25 PM
@bwoebi yes, if you copy something, then both parts will get the original blames
the point is that commits just moving or copying code should be ignored
 
@NikiC Err wait, I just interpreted the opposite from the manpage.
 
@NikiC Wait, is it doing something stupid like showing you changed every line? I don't use git often...
 
@Markberg I gave you more than enough information to clue you in on what is wrong. Try helping yourself before demanding others fix things for you.
 
@Charles yes
 
@NikiC That's pretty impressive. I didn't even think svn was that stupid.
 
6:27 PM
git isn't supposed to be stupid either
 
@NikiC nevermind, I misread.
 
at least if you pass -C
 
> This is a stupid (but extremely fast) directory content manager.
 
@derp practice on respect instead of php!!
 
@Markberg you wouldn't walk into a room full of strangers and demand that one of them help you, you shouldn't expect to get away with it on the internet ...
 
6:30 PM
@JoeWatkins :-(
 
hehe
> the information manager from hell
not much faith in what they were doing at the start ...
 
Jeez, C++ is in fine form today.
 
still says
> Git - the stupid content tracker
in readme today ... though description is a bit more optimistic ...
 
@JoeWatkins i know about pick head strategy and it is abvious
 
@Markberg no idea what you just said ...
 
6:33 PM
Is it can be tiny avatar time?
'cause seriously.
 
@JoeWatkins because u don't know anything about respect!
your friend disrespect me and you Defense his strategy
2
 
Social media scheduling fail: Joan Rivers promotes the iPhone 6 from beyond the grave: http://mirr.im/XuN3Rn http://t.co/QSmDr6pZCt
 
@Markberg You were "disrespected" because you made no attempt to understand the problem that was explained to you and then demanded an answer. That is disrespectful. Nobody is going to help you here with that kind of attitude. You'd may as well leave.
 
I don't think I done anything wrong ... the issue isn't me ...
 
@JoeWatkins lol
 
6:36 PM
This is why you don't help murderers move sofas. Lesson learned.
3
 
@Charles your friend could say it in polite way can't he
 
@ircmaxell she was so damn funny ...
epic fail tho
I love to think of hanks being a programmer ... nobody is allowed to ruin it for me ...
 
Yahoo's stake in Alibaba at $92 + cash from IPO ~= $44bn, which values the rest of Yahoo at minus-$4 billion.
 

« first day (1434 days earlier)      last day (3529 days later) »