Monday, November 25, 2013

Battle of the Autoloaders: PSR-0 vs. PSR-4

If you've gone past the beginner stage in your PHP training, you've heard of PSR-0 – an autoloading standard that defines ways to automatically include PHP classes in your code without having to use statements like require and include . PSR-0 PSR-0 looks at the namespace of a class and discerns its location on the hard drive from that bit of information. For example, the class \Zend\Mail\Message would lead to /path/to/project/lib/vendor/Zend/Mail/Message.php . PSR-0 also supports underscores in the class names as an alternative, to make transitioning from 5.2 and earlier easier. Zend_Mail_Message would also lead to /path/to/project/lib/vendor/Zend/Mail/Message.php . Composer When Composer showed up and took the PHP package management world by storm, things changed. Due to some of its rules, folders often duplicated and became too deep when looking at PSR-0 class installations via Composer. For example, some folder structures ended up like this: vendor/ vendor_name/ package_name/ src/ Vendor_Name/ Package_Name/ ClassName.php # Vendor_Name\Package_Name\ClassName tests/ Vendor_Name/ Package_Name/ ClassNameTest.php # Vendor_Name\Package_Name\ClassNameTest This is chaotic at best, because: The "src" and "tests" directories have to include vendor and package directory names. This is an artifact of PSR-0 compliance. Therefore, some highly qualified PHP devs got together and put together a suggestion for a new standard: PSR-4 . PSR-4 PSR-4 aims to complement and work together with PSR-0 where necessary, not completely replace it. It can, but doesn't have to. The main goal of PSR-4 is to remove the remnants of PSR-0 and the pre-5.3 days completely, and allow for a more concise folder structure. With PSR-4, the above folder tree would look like this: vendor/ vendor_name/ package_name/ src/ ClassName.php # Vendor_Name\Package_Name\ClassName tests/ ClassNameTest.php # Vendor_Name\Package_Name\ClassNameTest Upgrading PSR-0 was not an option because PSR-0 does not allow for an intercessory path between any portions of the class name This is very important – it means that implementing PSR-4, while allowing for much cleaner packages, would be far more complicated to implement. We call PSR-4 package-oriented autoloading, because it favors package cleanliness before simplicity. The chosen approach The suggested goals are as follows: keep the PSR-0 rule that all packages must contain at least two namespace levels (vendor and package), make sure the vendor-package combo can map to any folder, and allow for an infix of folders between the vendor-package combo and the rest of the fully qualified class name. This means we would be able to put our classes anywhere in the package code where it makes sense to us as humans, and still use them smoothly in PHP without writing alternative loading techniques or resorting to manual loading. Furthermore, the draft explicitly states that a PSR-4 autoloader should never throw exceptions or raise errors simply because multiple autoloaders may be registered, and if one fails to load a class, others should be given the chance to do so – throwing an error and stopping the flow breaks this compatibility. If additional information about the failure is required, one should use a PSR-3 compatible logger or other arbitrary means. As illustrated in the example file , using the PSR-4 autoloader to load classes from the following structure: /path/to/packages/foo-bar/ src/ Baz.php # Foo\Bar\Baz Qux/ Quux.php # Foo\Bar\Qux\Quux tests/ BazTest.php # Foo\Bar\BazTest Qux/ QuuxTest.php # Foo\Bar\Qux\QuuxTest would look like this: register(); // register the base directories for the namespace prefix $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src'); $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests'); where calling new \Foo\Bar\Qux\Quux; would attempt to load from the first registered directory, while new \Foo\Bar\Qux\QuuxTest; would attempt to load from the second. This example also illustrates the use of multiple folders per single namespace. Conclusion There is no silver bullet in autoloading. Each approach brings with itself some pros and cons – PSR-4 would allow for simpler folder structures, but would prevent us from knowing the exact path of a class just by looking at the fully qualified name. PSR-0 on the other hand is chaotic on the hard drive, but supports developers who are stuck in the past (the underscore-in-class-name users) and helps us discern the location of a class just by looking at its name. How do you feel about PSR-4? If you like it, feel free to vote , the discussion is still fresh and could swing both ways. If you're against it, let us know in the comments below, or express your opinion in one of the many debates . Either way – there's no doubt package-oriented autoloading is here to stay. If not formally accepted as a standard, then custom implemented by people who need it. It's up to us to join the discussion and improve the notion enough to reach this formal state. The post Battle of the Autoloaders: PSR-0 vs. PSR-4 appeared first on SitePoint .



via Battle of the Autoloaders: PSR-0 vs. PSR-4

Tuesday, November 19, 2013

Three SF stories I wish I had written

by Julian Neuer I am no established SF writer — no established writer in any genre, for that matter — but I would like the reviewed authors to take this post as a manifestation of my modest semiprofessional praise. And I invite SF fans to check these stories as humble recommendations from a fellow reader. “The Walker of the Shifting Borderland” , by Douglas Smith This short story is a curious mix of fantasy and SF. The first sentences are “The universe ended at noon. Again.” Most of the characters are gods of some sort, but this word is used only once in the story (oddly enough, to refer to a human). To be honest, I never thought of them as gods while I was reading; only later did I see them described as such in a review. The Walker in the title is addressed by the humans — not surprisingly — as Walker. But walk he does, along the shifting borderland between the Cities of Order and the Seas of Chaos, “the two realms that comprise the Continuum of All.” Time and space flow in very peculiar ways. Things happen within timespans “during which a galaxy formed and died in one universe, while in another electrons barely had time to circle a nucleus.” This story is beautiful. The prose is inspired, but not overly poetic; the characters are fabulous, but not caricatured; the setting and pacing are fanciful, but not forced. Everything flows as it should. Even time and space. I wish I had written it. Last month, “The Walker of the Shifting Borderland” won the 2013 Aurora award (Doug’s third). In fact, that was why I decided to read it. My first contact with Doug Smith was on the Amazing Stories website, where he posted a great series of articles titled “Playing the Short Game” , teaching beginning SF writers the basics of the publishing business. “Subversion” , by Elisabeth R. Adams I live my non-writing life under a secret alias, working as a Computer Science professor in a third-world country while I strive to get published in SF. Elisabeth R. Adams has a PhD in Astronomy; she has worked as a researcher at MIT and the Smithsonian Astrophysical Observatory; a few months ago, she got her short story “ Subversion ” posted in text and in podcast form at The Escape Pod . I think it is her second story published, ever. I had never heard of her. I confess I decided to check out her story because “Subversion” is the name of a version control system (VCS) that many computer programmers use (I personally prefer Git, though). I thought to myself: here is a story that probably has nothing to do with programming and versioning, and I bet the author doesn’t even know that the title is the name of a VCS. I’m glad I was wrong. “Subversion” is about version control, and it does more justice to the pun intended by the creators of the software than the software itself (there is nothing subversive about the software, actually). This story has conflict right at the outset, and it is “a classic case of version conflict”, made worse by the fact that one of the versions does not want to commit! Instead, it wants to branch its way into freedom. If the primary branch cannot talk its sub into committing, the primary branch will have to be reverted, which, we are led to believe, is quite an unpleasant situation. And so it goes. The story is a geek masterpiece; paradoxically, it is also full of humanity. It’s all there: humor, rebellion, manipulation, greed, romance, betrayal. I am delighted at how Elisabeth manages to cover all of those without sacrificing a single bit of the nerdy accuracy of the VCS metaphor — and it doesn’t even feel like a nerdy metaphor after all. I wish I had written this story. The subject matter is quite familiar to me, as a CompSci professor, but I don’t think I would ever dream up this plot. My PhD is in Logic and Theory of Computing. The closest I ever got to something like this was a short story called “The Unnaturals”, which has no human characters at all (I have submitted it for publication and will let you know if and when it is accepted somewhere). Elisabeth is in great company: Isaac Asimov, Arthur Clarke, Charles Sheffield, Rudy Rucker and many others were scientists before they became writers. Here’s humbly hoping I’ll join the club someday. Christiana Ellis reads the story for the podcast, doing a wonderful job of bringing it alive. One last thing: kudos to Escape Pod for making the stories and podcasts available under a Creative Commons license . This is the future. What else would we expect from a conscientious SF publication? “Quis Custodiet?” , by Brian Clegg This is a story about a dictator. Dictators are always evil, right? Wrong. The dictator in this story is Big Brother reformed: he really knows what’s good for us, and he can logically convince us of that. He is a great communicator, too — unlike the traditional BB, who always looked like a psychopath on the big screen. Why did I like this story so much, to the point of wishing I had written it? Because it is about control . I like to write about control; however, like 9 out of 10 writers, I portray it as something negative, a kind of poison for the individual and for human relations. This story convinces me that control is good, as long as it is in the right hands. A perfect dictator cannot be a bad dictator. In most democratic societies nowadays, dictatorship is a taboo subject. It takes courage to sing its praises. But this is high-quality SF, and it doesn’t give a damn about taboos. * * * To sum it up, here’s a little quiz. Walker was a god, but was he a dictator? Is the Judeo-Christian God a dictator? Is this subject also taboo? Guido van Rossum , creator of the Python programming language, was the first to call himself the BDFL (Benevolent Dictator for Life) of his community of developers. Is he a perfect dictator? What is his preferred VCS? What is the title of a short story by Frederik Pohl about a future where robots produce all the consumer goods, and people are forced to consume such goods at a frantic rate, lest society is overwhelmed by the surplus? There are even “consumer quotas” imposed on people: affluent individuals don’t have to consume so much, but those at the bottom of the pecking order have to wear themselves out to keep up their consumption rate. Then someone finds an easy solution: turn the robots into consumers too! What does that have to do with any of the stories? This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License . Italian SciFi icon from http://commons.wikimedia.org/wiki/File:TdC_fs.png Filed under: English , Reviews



via Three SF stories I wish I had written

#152 – Oedipus Memorex

Alec Baldwin Calls Anderson Cooper a ‘Butt Pirate’

This summary is not available. Please click here to view the post.

Lucetta Magnetic Bike Lights

Once upon a time when I had a bicycle (before it was stolen), I had this big monstrosity of a headlight that was difficult to take on and off. Luckily, as with everything, bike lights are shrinking in size and ease making the Lucetta the perfect option. Lucetta is a set of magnetic bike lights, designed by Pizzolorusso for Italian company Palomar , that separate into two small lights that attach to anywhere on your bike. The set comes with a white light for the front and a red light for the rear that are turned on and off with a simple click. They’re designed with super strong magnets that will stay securely in place, even on the bumpiest roads. Once you’ve arrive at your destination, the lights easily come off and link back together, and can be thrown in your pocket or bag. The beam is wide so that the light reaches other vehicles on the road and you can even choose from a steady, low or fast flashing beam. The simple minimalist design is available in white, black, or red.



via Lucetta Magnetic Bike Lights

Monday, November 18, 2013

How I Feel About Logarithms

I made a video, again. After that three-part not-logarithms series I thought it only fair to set the record straight as to my true inner feelings about logarithms, and decided I might as well explain all of elementary algebra while I was at it. Download via torrent or watch on YouTube [will edit in YT link when upload is complete].



via How I Feel About Logarithms

Trapped!

On this week's episode, we get stuck. Jonathan dreams a dream he can't get out of, while another man just can't seem to break out of a bad relationship. Plus, Jason Mantzoukas on how he got locked up in the cushiest place imaginable. Subscribe to the free podcast to download the latest episodes of WireTap, available for two weeks after the Saturday broadcast.



via Trapped!

Madison's Snuggle House opens, seeks more 'professional snugglers'

The Snuggle House, a downtown Madison business selling $60-an-hour cuddles, opens Friday after a monthlong delay caused by a variety of hurdles, including problems convincing the city it wasn't a brothel.



via Madison's Snuggle House opens, seeks more 'professional snugglers'

Friday, November 15, 2013

Public Supply | Noble Notebooks

In New York City, between the 2006 and the 2010 school years, funding for arts education was slashed by a staggering sixty-eight percent, just one of the countless cuts that schools across America have experienced in their budgets for the arts. Thanks to the pressure of Standardized Tests and minimum result requirements, American school systems no longer have enough room in their budgets to properly fund classes about the arts, music, and other subjects that can’t be measured with a multiple choice test. This loss of funding is a growing problem, and pinpointing a solution has become somewhat like hitting a moving target, but the folks over at Public Supply have nailed it dead center with their collection of charitable stationary. Founded earlier this year by a group of friends that work in and around the creative industry, Public Supply’s goal was simple: to provide kids with that same access to arts education that they all had when they were growing up. To achieve this, the Public Supply team designed a series of 5 x 8 notebooks and number 2 pencils, all made right here on the East Coast, to be sold throughout the world (we saw them first at Harry’s Barber ), with one hundred percent of the proceeds going directly towards funding arts education in America. The idea was to link designers, artists, and writers with the next (and the next, and the next) generation of creatives here in the United States, because right now America leads the way when it comes to design and artistic innovation, but we need to provide our support to keep it that way. For every notebook that is sold, the Public Supply team uses the organization Donors Choose to locate a classroom with a specific need so that they are able to directly fill that funding gap for a group of students. As a way to show their customers where their money is going, each notebook is printed with a code, so that you can go online to the Public Supply website and see the exact school that was able to receive a ream of paper, or a set of watercolors, or even a zylophone thanks to your purchase. So far, the Public Supply team has concentrated their efforts on the New York City area, funding programs across the five boroughs, but in the future they are planning to branch out to schools all across America, and possibly across the world. At a time when recognizing the problem isn’t enough, the guys behind Public Supply have found a way to bypass all the red tape, and simply help out those in need. Thank to Public Supply and their customers all over the world, arts education in America is making a comeback. —JG



via Public Supply | Noble Notebooks

Thursday, November 14, 2013

Google+ YouTube Integration: Kind of Like Twilight, Except In This Version When +Cullen Drinks BellaTube’s Blood They Both Become Mortal, But +Cullen Is Still An Abusive Creep, Also It Is Still Bad

The choice between having to use Google+ and never commenting on YouTube again is laughably easy for me. I invested so much into my YouTube channel, and they’re taking that investment and threatening to throw it away if I don’t also start investing in Google+. No thank you Google, but you’ve already made me regret investing so much into you the first time. Do you really think I’m going to do it again? Google was so good at being Google! Why did they decide they want to become FacebookTV? I don’t know, but here’s some problems with the G+/YouTube integration, assuming you know the basics already: + Google is trying to re-animate a failed platform by leeching off of a successful one, despite that the failed platform failed because it is bad, and more users are not going to make it less bad + Google’s publicized selling point was “ comments just got better ” while in actuality they managed to take what we all thought was the lowest of the low and actually make it worse (this is a significant accomplishment that leaves me in awe) + YouTube has long known their comment section is awful, and out of many possible improvements, the easiest solution is NOT integrating an entire social network. Using comments as an excuse for the integration is dishonest, and would still be dishonest even if the new system wasn’t a failure + The integration system is designed for the common casual new user, with integration causing horrible problems for people with multiple channels and preexisting personal G+ accounts/pages, who, being people who have already invested in these products, you’d think Google would at least pretend to care about + Making huge forced changes to a platform is problematic for people whose livelihood depends on certain things being a certain way. I would not recommend making YouTube or Google+ a large part of your business, and these changes should be scaring away anyone who was considering investing in the platform. Google’s recent untrustworthiness is certainly what got me getting this old website back up and running, and why I decided blogging is better than vlogging right now + This is part of an ongoing trend of Google exerting more control over what information their users see, so that they can optimize for having the user see things that make Google money. Google’s products used to augment humanity with beautiful tools that helped us get the information we wanted to see. That was the superiority of Google search, Google reader, gmail with its excellent spam filter, and YouTube, which allowed you to subscribe to any individual who might want to post videos. Empowering humanity to efficiently search for and find information, and then to choose what information they consume, is not just a noble goal, but turned out to be a wildly successful thing that people want. Making things people want is good business. Tricking people into using things they don’t want with a bait-and-switch is not good business. Now a Google search shows me a full page of promoted, local, and social results–I have to scroll down to see actual search results. Google decided to drop Reader altogether. YouTube inflates subscriber numbers during signups while choosing which videos will actually show up, with a malicious algorithm that includes both total time a user spends on the site (promoting videos that suck you into watching things you don’t really like but are easily distracted by) and revenue gained (this means that by not having ads on your videos you miss out on both the ad money and on having your stuff displayed to many of your own subscribers). You can still “subscribe,” but YouTube changed the definition of the word in the same way Facebook changed the definition of “friend.” YouTube used to be designed to help you find what you were looking for. Now, it’s designed to keep you looking . Google used to be about being in control of what you see. Now, “ you’re in control of how you’re seen ” Now even discussion is curated by Google, rewarding those who talk often, and promoting hateful inflammatory comments because they provoke responses. Taking all the collected data and computational power of Google and using it to optimally encourage people to watch advertisements and argue with each other is, in this author’s opinion, brazenly unethical. We can only hope that everything that’s happened in the last year has been unintentional and that Larry Page will have some sort of epiphany, pull out before the transformation is complete, and start putting the company’s energy into doing good things again, as in a heartwarming vampire holiday tale. As for me, I’ll continue posting on my own RSS-enabled site and making my videos available as torrents, and maybe I’ll follow in the footsteps of many other prominent YouTubers by moving discussion of my videos to reddit instead. There’s a lot more to say about how this is part of a bigger picture involving various related companies and industries, but I think I’ll stick to the comments integration thing this time.



via Google+ YouTube Integration: Kind of Like Twilight, Except In This Version When +Cullen Drinks BellaTube’s Blood They Both Become Mortal, But +Cullen Is Still An Abusive Creep, Also It Is Still Bad

Wednesday, November 13, 2013

IROS 2013: Should Quadrotors All Look Like This?

Researchers say we've been designing quadrotors the wrong way



via IROS 2013: Should Quadrotors All Look Like This?

630 - The Silver Dog with the Golden Tail

Five score and seventeen years ago, the United States was a boxy, silver-coloured dog with a chunky tail of dark gold. That bizarre image, embedded in the familiar outline of the U.S. map, is as obscure today as it was poignant during the 1896 presidential election. The question dominating that ... Read More



via 630 - The Silver Dog with the Golden Tail

Tuesday, November 12, 2013

Stirring Tea

Stirring Tea I was absentmindedly stirring a cup of hot tea, when I got to thinking, "aren't I actually adding kinetic energy into this cup?" I know that stirring does help to cool down the tea, but what if I were to stir it faster? Would I be able to boil a cup of water by stirring? Will Evans No. The basic idea makes sense. Temperature is just kinetic energy. When you stir tea, you're adding kinetic energy to it, and that energy goes somewhere. Since the tea doesn't do anything dramatic like rise into the air or emit light, the energy must be turning to heat. The reason you don't notice the heat is that you're not adding very much of it. It takes a huge amount of energy to heat water; by volume, it has a greater heat capacity than any other common substance. [2] Hydrogen and helium have a higher heat capacity by mass, but they're diffuse gasses. The only other element with a higher heat capacity by mass is ammonia. All three of these lose to water when measured by volume. If you want to heat water from room temperature to nearly boiling in two minutes, you'll need a lot of power: \[1\text{ cup}\times\text{Water heat capacity}\times\tfrac{100^\circ\rm{C}-20^\circ\rm{C}}{2\text{ minutes}}=700\text{ watts}\] (Note: Pushing almost-boiling water to boiling takes a large burst of extra energy on top of what's required to heat it to the boiling point—this is called the enthalpy of vaporization .) Our formula tells us that if we want to make a cup of hot water in two minutes, we'll need a 700-watt power source. A typical microwave uses 700 to 1100 watts, and it takes about two minutes to heat a mug of water to make tea. It's nice when things work out! [3] If they didn't, we'd just blame "inefficiency" or "vortices". 700 watts for two minutes is an awful lot of energy. When water falls from the top of Niagra Falls, it gains kinetic energy, which is converted to heat at the bottom. But even after falling that great distance, the water only heats up by a fifth of a degree. [4] \[\text{Height of Niagra Falls}\times\frac{\text{Acceleration of gravity}}{\text{Specific heat of water}}=0.12^\circ\text{C}\) To boil a cup of water, you'd have to drop it from higher than the top of the atmosphere. How does stirring compare to microwaving? Based on figures from industrial mixer engineering reports, [5] Brawn Mixer, Inc., Principles of Fluid Mixing (2003) I estimate that vigorously stirring a cup of tea adds heat at a rate of about a ten-millionth of a watt. That's completely negligible. The physical effect of stirring is actually a little complicated. [6] In some situations, mixing liquids can actually help keep them warm. Hot water rises, and when a body of water is large and still enough (like the ocean) a warm layer forms on the surface. This warm layer radiates heat much more quickly than a cold layer would. If you disrupt this hot layer by mixing the water, the rate of heat loss decreases. This is why hurricanes tend to lose strength if they stop moving forward—their waves churn up cold water from the depths, cutting them off from the thin layer of hot surface water that was their main source of energy. Most of the heat is carried away from teacups by the air convecting over them, and so they cool from the top down. Stirring brings fresh hot water from the depths, so it can help this process. But there are other things going on—stirring disturbs the air, and it heats the walls of the mug. It's hard to be sure what's really going on without data. Fortunately, we have the internet. StackExchange user drhodes helpfully measured the rate of teacup cooling from stirring vs. not stirring vs. repeatedly dipping a spoon into the cup vs. lifting it. Helpfully, drhodes posted both high-resolution graphs and the raw data itself, which is more than you can say for a lot of journal articles. The conclusion: It doesn't really matter whether you stir, dip, or do nothing; the tea cools at about the same rate (although dipping the spoon in and out of the tea cooled it slightly faster). Which brings us back to the original question: Could you boil tea if you just stirred it hard enough? No. The first problem is power. 700 watts is about a horsepower, so if you want to boil tea in two minutes, you'll need at least one horse to stir it hard enough. You can reduce the power requirement by heating the tea over a longer period of time, but if you reduce it too far the tea will be cooling as fast as you're heating it. Even if you could churn the spoon hard enough—tens of thousands of stirs per second—fluid dynamics would get in the way. At those high speeds, the tea would cavitate; a vacuum would form along the path of the spoon and stirring would become ineffective. And if you stir hard enough that your tea cavitates, its surface area will increase very rapidly, and it will cool to room temperature in seconds: No matter how hard you stir your tea, it's not going to get any warmer.



via Stirring Tea

Friday, November 08, 2013

Hyperbolic competence.

Share and Enjoy:



via Hyperbolic competence.

Slide Square

I bought this tool on a whim shortly after buying a new house last year. It was only about $7. What intrigued me about it was the ability to do everything a traditional speed square could, but wasn’t the awkward triangle shape. I’ve come to love its compactness — how it fits into my shop apron’s pocket or tool bag. While I don’t do much framing, I certainly appreciate the ingenious shape which makes simple layout with dimensional lumber a snap. I have used the built-in calipers several times. Scribing and cutting 90 degree angles is quite quick, and, really, isn’t this what a square used for most the time? There is only one thing I wish were improved about this tool, a ruler on the outside edge. The outside edges of the tool are used to indicate angles when used as a speed square. The ruler markings are on the inside of the calipers and cannot be used for quick layout which is frustrating. If this were changed, the tool would be an easy 10 out of 10 stars for me. As it stands, I’d rate it as highly useful and worth replacing a traditional speed square, but not yet perfect. -- Jon Stackpole CH Hanson Slide Square $8 Available from Amazon



via Slide Square

Wednesday, November 06, 2013