|
Thanks! Have a bunch of 5s!
|
|
|
|
|
Anyway, to address some points...
Marc Clifton wrote: I despise silent exits, not even a little whimper of "$foobar" not defined.
Completely configurable. Use the debug version of php.ini that ships with your distribution while doing development. Error messages like this are turned off by default for production and for a good reason, you're supposed to have proper error handling.
Marc Clifton wrote: I detest prefixing variables with "$", it harks back to the days of BASIC ass$="you are".
That has to do with its Unix roots man. If you're done a lot of Perl and shell scripting, you'd be very familiar with the good ol' $ .
Marc Clifton wrote: I piss on your brace style if ( condition ) {
Come on Marc, really?
Marc Clifton wrote: Which of course promotes non-OOD spaghetti code practices, which is what I'm fixing right now. It's a amazing to me how people can f**** up less than 500 lines of code into an untestable morass of garbage.
True, PHP allows for OO and procedural code. And that allows for crap code by some dev. But C++ also allows you to shoot yourself in the foot and we don't blame the language.
Jeremy Falcon
|
|
|
|
|
Wow. Thanks for the feedback. I will fuss with the ini file, that'll be really helpful as, without intellisense, I make a lot of stupid mistakes.
Speaking of which, I'm using this nifty plug-in (it's something like $75) for Visual Studio that does a lot of the syntax highlighting and intellisense stuff, and most awesome of all, I can debug PHP code right in the IDE!
Jeremy Falcon wrote: Come on Marc, really?
I know, that was low. I really don't like that style of bracing though, I find it harder to visually distinguish code outside the if block with code on the inside.
Again, thanks for the great feedback!
Marc
|
|
|
|
|
Marc Clifton wrote: Speaking of which, I'm using this nifty plug-in (it's something like $75) for Visual Studio that does a lot of the syntax highlighting and intellisense stuff, and most awesome of all, I can debug PHP code right in the IDE!
You and me too man and I use PHP daily. And yet, at the age of 35 me and intellisense are best buds Also, I've seen that plug-in, if I wasn't using PhpEd like crack-cocaine I'd give it a whirl.
Marc Clifton wrote: I know, that was low. I really don't like that style of bracing though, I find it harder to visually distinguish code outside the if block with code on the inside.
Not sure I follow. It's no different than the C-family where white space is not important. This is perfectly valid PHP code:
<?php
namespace Application;
class MyClass extends BaseClass
{
public function MyFunction()
{
if(blah)
{
}
}
}
?>
Marc Clifton wrote: Again, thanks for the great feedback!
Any time man, you know I got your back. Ask away any question you have.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Any time man, you know I got your back. Ask away any question you have.
I just had fun with this little piece of code:
array_walk_recursive($xmlResponse, array ($xml, 'addChild'));
Turns out array_walk_recursive passes the K=>V as $value, $key, and the XmlSimpleElement of course wants $element, $value.
Now, I did not write that code, I'm just fixing what someone else wrote. Sure was funny though when (after considerable massaging) I ran my unit test and the element/values were backwards! It is odd though that array_walk_recursive doesn't provide the params as $key, $value, but it's actually much more annoying that the programmer who used that function used it incorrectly for the task at hand.
Marc
|
|
|
|
|
Oh you're gonna find some "oddities" in there like that. I totally agree it would make more sense to order it key then value, like when doing a foreach loop.
That being said, there are better ways to traverse an XmlSimpleElement object. Unless it's been properly converted, treating it as a straight array will run into issues, and you'll loose XML metadata attributes, etc.
At the very least, if you're using PHP 5.5, you could do something like this with an anonymous function to at least make it a ton more readable...
array_walk_recursive($xmlResponse, function($item, $key)
{
});
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: That being said, there are better ways to traverse an XmlSimpleElement object.
In this case, "xmlResponse" is an array to generate the XML response. As it is, I simply coded it like this:
function XmlAsString($array)
{
$xml = new SimpleXMLElement('<response/>');
foreach($array as $key => $value)
{
$xml->addChild($key, $value);
}
return $xml->asXML();
}
which does correctly what was originally intended.
I'm having to use PHP 5.4, but I like your anonymous function example, very cool. I think that actually works in 5.4 as well, but not sure.
Marc
|
|
|
|
|
Marc Clifton wrote: which does correctly what was originally intended.
Gotcha. Yeah that first example did not get that point across at all. My condolences.
Marc Clifton wrote: I think that actually works in 5.4 as well, but not sure.
Yup, 5.4 should support them too. Ever since 5.3 I think.
Jeremy Falcon
|
|
|
|
|
Oh one thing I should say is there is a bit of type safety in PHP. For instance, you can ensure a passed parameter is an array or type of object. The loose type thing is more for intrinsic simple types. Using your example...
function XmlAsString(array $array)
{
$xml = new SimpleXMLElement('<response/>');
foreach($array as $key => $value)
{
$xml->addChild($key, $value);
}
return $xml->asXML();
}
Notice the function signature now. If an array is not passed to it an error will be thrown.
Jeremy Falcon
|
|
|
|
|
Javascript is a lot worse, at least in PHP you can configure it to give "variable not defined" warnings (error_reporting(E_STRICT);)
|
|
|
|
|
Give us a free C# based scripting language that runs on cheap Linux boxes as easy as PHP and we'll use it...
|
|
|
|
|
Still, it's a little goofy that I did not win anything yet. It would be great to see the winning combinations and how much is currently in the jackpot. And perhaps some animations...
What do you mean, CP does not have a slot machine? It's right there, the orange bar above the posts! The four windows are labeled 'Spacing', 'noise', 'Layout' and 'Per Page'. Ok, must be some kind of theme.
Anyway, when I come to CP from work, I am usually not logged in and every time there are totally random settings in this bar. It's very irritating. How did you program this anyway? I hope you did not really use a random number generator to annoy those who are not willing to log in.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
|
|
|
|
|
We use a random number generator.
cheers
Chris Maunder
|
|
|
|
|
Great! So, what are the prizes?
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
|
|
|
|
|
The logic is:
1. If you're logged in, get your preferences based on your member ID
2. If not, get your preferences based on a cookie.
If you have a cookie and then log in, and you already have preferences associated with your membership, replace your cookie'd preferences with your member preferences. The algorithm to work out which preferences to use in a tie-breaker scenario are known only to two people on the planet who are not allowed to fly on the same plane at the same time.
If you then log on using another machine you'll get your merged preferences. If you have cookie settings on that second machine then they too will get merged.
So: if you've been changing your settings on lots of different machines while not logged in, eventually, when you log in on those machines, your preferences will get combined.
If you're seeing our Random Preference Generator™ in action while logged on on two different machines then send me an email (chris@...) and I'll dig in.
cheers
Chris Maunder
|
|
|
|
|
It's always the same computer, from which I never ever logged in. Nor have I ever changed my preferences on this computer here at home. Still, I get a random combination of the four options every time at work.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
|
|
|
|
|
I get the same type of thing on my work "net nanny" machine. Pretty annoying, but figured since I wasn't logged in, it was normal but unfortunate behavior. Especially since their proxies make everything about 10* slower, turning a decent machine into a f'ing POS.
Ken
|
|
|
|
|
Would be awesome if true
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Reminds me of a few years back, when a mate of mine asked if it was possible to use a program to calculate daily lucky numbers (I know some weird people).
For a laugh, I rattled off a proggy that went through numerous pages of stupid personal questions that I said were used in the calculation (my fave being "What size shoes do you wear?" and "How do your shoes feel, today? Tight | Loose | Just Right").
When they finished entering all the information, I printed a "lucky number" from a random number generator.
I got loads of feedback from him and his pals saying how accurate and useful it was, and how it was amazing that it worked so well and helped them so much.
Oh, and the most fun thing was that, although I saved all the details to profile .ini files (it was in the Win 3.1 days), I never read them in, so they had to fill out every page every time they used it.
I've never done any other coding during which I laughed so much.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
So...you're laughing and they're going to the bank?
|
|
|
|
|
Hey, if someone gets a windfall and gives me (or, rather, a random number that I generated for them) credit for their gain, I'm OK with that.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Pure gold.
cheers
Chris Maunder
|
|
|
|
|
I have always being fascinated with this. Coming from India, we are presumed to hate people from Pakistan. However, every single time I have met a Pakistani, it has been a pleasure.
I do not want to go into politics or anything else. A simple question:
As a normal Indian citizen, I have no hatred against any normal Pakistani citizen. Have you ever felt severe hatred against an entire nationality? If yes, why? And if not, what is the most ridiculous stereotypical hatred you are expected to show?
No politics and religions please. Straight up answers. If you want a discussion, we can always go to Backroom.
|
|
|
|
|
I'm pretty sure this will need to go to the 'other place'.
|
|
|
|
|
I know. But I guess, straight up answers posing opinions shouldn't hurt lounge.
|
|
|
|
|