Out of nowhere I hear someone at the other end of the office (we share with two other companies) blurt out, “over half of the web is flash.” This person always leaves his door open and talks loudly, so I've learned to tune him out, but this line grabbed me. First, I feel this number is wrong. Second, there is no way to know with a good amount of certainty what the percentage is. From the continuing context, I learned that he was talking about the iPad and its lack of Flash support, criticizing Apple for becoming “the next Microsoft”—whatever that means. He concludes with saying an increasing amount of developers are starting to program for android.
This whole conversation triggered feelings of anger and frustration at this person. I hate Flash; I hate Flash a lot. But this is not because Flash is not supported on the iPad, or that it is full of security holes, or that distributing unchecked byte-code is an inherently bad idea. I hate Flash because it is closed source, anti-freedom software controlled by a single entity interested only in financial gain.
Do I have Flash installed? Yes, and according to certain surveys, up to 99% of internet users have Flash installed. And it disgusts me. I try to not install it, or run it only in controlled virtual environments, but it is ubiquitous. Many “social marketing” companies promote using sites like YouTube, which almost exclusively uses Flash for its videos, so when clients ask for YouTube, I reluctantly grant.
But while I concede to its use when necessary, I never create new material using Flash and whenever possible evangelize open technologies and Free/Libre alternatives. And I beseech you, reader, to also stop developing for or using Flash.
One of the best parts of my previous job—and also the part that kept me going for so long—is that I had the chance to work on a variety of projects, in many cases for completely different business ventures. One week I had been privileged with the task of writing a small program which ended up being semi-intelligent (of course artificially, thus AI). As it so happens I also seemed to have stretched PHP to its limits.
When originally typing up this post, I kept the details to a minimum, but now that I've moved on I can freely discuss it. This program—code-named “twitterbot”—was tasked with searching Twitter for tweets with certain keywords within a radius of a location, like for tweets containing "hungry" within 30 miles of Minneapolis, and @reply to that person within an hour of their tweet about ... a website I probably shouldn't name. However this becomes tricky since Twitter is really good at detecting spam, and a lot of Twitter users really hate spam (like me). To get around it, I made a bunch of twitter accounts using anonymous email addresses, created bios, set profile pictures, and set color schemes, all to make them look like real people.
However, just because a Twitter account has a profile picture, it does not mean it will be treated like a human: the account has to have realistic-looking posts. No problem. First I set a limit to the number of posts an account can make per day, make sure all the posts are within normal waking hours (like 6am to 10pm), have 30-50% of the tweets be the spamming tweets, and the rest be copies of tweets from a different search that none of the accounts will be replying to. Then since the spam tweets themselves are also randomized, the sum of it all equals twitter accounts that even people are sometimes not able to recognize that the account is a bot.
For the technical, I wrote this program in PHP both because we had thousands and thousands of lines of legacy code in other programs that we didn't want to touch, and second because it is extremely simple and quick to code and deploy. With a semi-AI bot though, the scene changes and suddenly both opportunities and concerns that weren't there before suddenly are. Example opportunity: pcntl-fork becomes available. Example concern: the PHP program will probably be running as a daemon on a server, use up all your RAM and explode.
In the end, the bot ran strong for about 2 weeks before management changed their minds and had it shut down—spamming people does not make for good press. I felt terrible having to write such a program; I really don't like spam, let alone being the one doing the spamming. But since then I've moved on to a position at a different company and write ethical code now.
Any programming environment with more than one person working on the same project requires communication; it is an essential part of getting a job done efficiently, and it is common sense. But while normal business communication includes writing, speaking and body language, programming communication also includes readability of code along with good documentation.
Having experience with coding in a large project with other people, I clearly see that indentation is a large part of readability of code. It is extremely important to be consistent with spacing regardless of the language. However, whether to use tabs or spaces for indentation is up for debate. In fact, the issue of tabs versus spaces is a highly debated issue; a simple search will show that. Even so, it is important to have a clearly defined rule when engaging in a project with other people.
To show the importance of this many different open source projects define strict guidelines for indentation. To list a few:
Most of these say 4 spaces for per indentation level, and all say to never mix tabs and spaces. I do 4 spaces; my programming team at work has agreed on 4 spaces—it works really well in pretty much all cases. All good editors have ways to make this easy to do using the tab key too.
More than likely the language you code in already has some guide already. Please follow it, and remember what the Zen of Python states: “Readability counts.”
In August I wrote about Application Shortcuts for Chrome and noted that this new concept had the potential of being useful since I don't like using standard desktop clients for email due to their lack of full Gmail support (like labels and the archive). Now having taken a further look, I'm not so convinced.
Application shortcuts are created by clicking on the "Page" button and selecting "Create Application Shortcuts...". If you select to create a shortcut on the desktop, Chrome then creates the Application Shortcut and puts it on the desktop. All this is simple enough, but what it actually does is make a shortcut to Chrome at the current page and passes the --app flag.
I invite you to try this for yourself with something like Gmail and see what you think. When launched, a Chrome window is open without the tab bar or address bar. The confusing part is that internally, it is treated like a normal Chrome process. So cookies are shared with any open tabs in a normal Chrome window. Why would I want that? If this is supposed to be a Gmail App, wouldn't I want cookies to be separate? What if someone else needs to check their email quick and I have the App open? I get logged off in the App and their session is replaces mine.
The Chromium bug list has a feature request for this, but it hasn't received much attention.
PHP class methods and variables can be declared as static similarly to how Java static methods and variables work. As often as possible I try to stay away from anything static in PHP, since it can lead to confusion, bad program design, and in some cases memory management problems. But sometimes it actually does make sense and more often than not just getting things done is more important than doing things correctly.
However, PHP 5.3 introduced a lot of cool new features like namespaces and something called “Late Static Bindings” via a new keyword. But what is Late Static Binding and how does it differ from how PHP before 5.3 works? The reason the new static keyword was added is to allow for intuitive static references involving inheritance.
Before 5.3, PHP used early static binding: the process of resolving any static references to the class where it was initially declared. Clear as mud right? This is best shown by the code example from the PHP documentation.
<?php
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
self::who();
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::test();
?>
The above code will output A not the (maybe) expected B. Replacing self with static in the example will output B, but only in 5.3 and above.
Since none of the servers I work with have 5.3, and some are even lacking 5.2, I cannot take use of the static keyword in my code. But even so, I feel like I understand PHP better now that new feature is available since this clearly shows that using self in any version will use “Early Static Binding.”
When I speak my mind about things I have opinions about, I normally get myself in trouble. For example, when I tell people I am a skeptic—they look at me funny and start ignoring what I say. Today, I saw this video and was appalled. USA has some messed-up politics, but we have a pretty spectacular constitution when compared to other governments around the world.
Apologies for the graphic nature of this, but it needs to be seen. I don't know the context of this event or the outcome, but if this is a good representation of the state of the government in Iran, I fear many more atrocities are taking place.
As a programmer in the US, I often obsess over little things like whether to use tabs or spaces in a PHP file, or why Internet Explorer 6 renders some CSS so terribly. And while I have the right to, sometimes I feel like I should be doing more. So since I have control over this blog, I share this video with you with the hope that the basic rights these people need may be granted to them.
I had a fun two weeks with Django, but now it's over. There is nothing wrong with Django, in fact page load times went from about 1-1.5 seconds to about 100-300 milliseconds. I haven't narrowed down why yet—maybe python over php, maybe InnoDB tables instead of MyISAM, maybe mod_passenger instead of fastcgi. While I plan on trying to figure it out later, Wordpress just plain works. If I need to type a post, wordpress lets me do that really simply. For some reason, Dreamhost doesn't like some of the admin urls I use and I really do not have time to figure it out. So, hello Wordpress 2.9.
I decided to keep the new theme, but I put ads back on the site again. I will not ask you to click on them, that would be violating the Terms and Conditions of having them there, but in case if someone does happen to find something useful in them, I get a few cents from each click.
I wrote down this conversation I had with a co-worker the other day. I just found it, and thought I would share it.
me: how do i tell php to be smarter? co-worker: you have to enable that in your php.ini me: oh of course co-worker: but you have to make sure php was compiled with the --smart flag me: dang
Lots of changes are happening around here. I will no longer be offering ads on my blog for starters. I don’t like ads and I‘m guessing you don’t either. My services involve programming, and I want to make a living by legitimately doing work, not stealing money by people clicking on ads.
In other news, my blog now uses the Django web framework. I am really happy to move away from Wordpress as I now have complete control over my database schema. Django provides a great framework for making web applications quickly and efficiently—if you haven’t noticed this page probably loads much faster.
However, I wrote the RSS feed from scratch, so if you have problems with it, please let me know.
For some time I've been working with web frameworks. Finding a good web framework is not hard with PHP since so many exist already, but since I've fallen in love with Python I've discovered Django. Recently, I've been re-building this blog using Django (more on that to come later) and to my surprise, using a well-developed MVC Framework with a thought-out database schema makes traditional development almost non-existent and lets me focus on theming.
Since my job is mainly PHP and MySQL development, I don't do a lot of theming. I actually like coding CSS, but we have a design team for that. For this blog, it's actually something I need to think about. I've done a lot of CSS coding, but recent events at work have left me frustrated with legacy code, thus sparking this post. So getting to the point: CSS is not an art. Cross-browser CSS is not something one intuitively picks up and starts playing with, it is a language, and to be successful at it you need to know what you are doing.
The key concept is the possibility of writing unsuccessful or bad CSS. The art is drawing up what the page is to look like—concept art, or as some call it “mocking up” a page. CSS is the tool used to get the page to actually look and function as intended, and in every browser. I believe a lot of amateur web developers do not realize the importance of understanding both the CSS specifications themselves and how each CSS command will affect each web browser.
To further my point, this week I've been working with more legacy code which has CSS sprinkled all over, and always as an afterthought. This itself is not necessarily bad, as sometimes the importance of getting something semi-functional (or to a state where your boss stops yelling at you) necessitates ignoring certain parts of the process. In this, Internet Explorer 7 was forgotten about and somehow hovering over a certain set of <span> tags makes large parts of the page shift a few pixels back and forth. In an extreme case, it would hinder someone from using the application and potentially cost the company money—again an unacceptable outcome.
Having been dealing with CSS for a number of years now, I feel like I've learned quite a bit about how each browser treats different CSS attributes, but new web technology is embraced at a quick pace, and I still find new awkward Internet Explorer rendering engine bugs on a consistent basis. But at the least, having an understanding of what CSS was built to do goes a long way.