December 10, 2010

Happy Holidays from Adobe!

Every year, Adobe helps us celebrate the holiday season by giving us a fun and interactive way to share the spirit!

This year is no different!  We often have a theme for each year, and I happen to love this years theme – turning inspiration into action.  We’re asking you to share what it is in your life that inspires you, and in return, we’ll donate $1 per response to Mercy Corps with the goal of donating $25,000!
 

Adobe Holiday Card 2010

 
So, share the inspiration and share the love!

If you’re on Twitter, please tweet:
• What inspires you? Share with us and we will donate $1 to @MercyCorps. Happy Holidays from @Adobe! http://bit.ly/AdobeGreet

If you’re on Facebook, please share:
• What inspires you this holiday season? Share your thoughts with us and we’ll help turn inspiration into action by donating $1 to Mercy Corps. Happy Holidays from Adobe! http://bit.ly/AdobeGreet

Happy Holidays!

*I love this time of year :D

 

Charles

5:44 PM Comments (0) Permalink
December 7, 2010

JavaScript Puzzler – Let’s Print Some ZIP-Codes!

Let’s take a look at a JavaScript Puzzler. If you don’t know what a Puzzler is, it is essentially a short problem used to demonstrate a quirk or edge-case with the language that you might encounter. Here is the format:

  1. Code – I introduce the code
  2. Question – I pose a multiple-choice question and you guess what the outcome is…think hard!
  3. Walkthrough – I walk through a reasonable explanation
  4. Answer – I tell you the real outcome (it might surprise you), and explain why
  5. Moral – How can we avoid making mistakes like this in our own code

Now that we all know what a Puzzler is, here is a simple JavaScript Puzzler:

Code:

<script type="text/javascript">
 
	// array of 6 valid zip-codes
	var zipCodes = new Array("93021", "16284", "02392", "20341", "08163", "32959");
 
	// let's do something with each zip-code - for now, print them out
	for (i = 0; i < zipCodes.length; i++) {
 
		// sanity check
		if (!isNaN(parseInt(zipCodes[i])) && parseInt(zipCodes[i]) > 0) {
			document.write(parseInt(zipCodes[i]) + " ");
		}
 
	}
 
</script>

Question:

What does this print?

  1. 93021 16284 2392 20341 32959
  2. 93021 16284 2392 20341 8163 32959
  3. 93021 16284 20341 32959
  4. none of the above

Walkthrough:

So, we have an array of 6 ZIP-codes in string format. We iterate through each one and print it, but first we do a sanity check. Let’s walk through each number and see if it passes.

  • 93021 – This will return a number and it will be greater than 0, so “93021″ will be written.
  • 16284 – This will return a number and it will be greater than 0, so “16284″ will be written.
  • 02392- This number has a leading 0, but parseInt() will just trim it. So, this will also return a number greater than 0, and “2392″ will also be printed (Note: no leading 0).
  • 20341 – This will return a number and it will be greater than 0, so “20341″ will be written.
  • 08163 – The same as the other number with a leading 0, parseInt() will trim this and return valid number, so “8163″ will be printed (Note again: no leading 0).
  • 32959 – This will return a number and it will be greater than 0, so “32959″ will be written.

Therefore, we should see all six numbers printed, with the numbers that have trailing 0′s being trimmed. So, my answer is b, this code will print the string “93021 16284 2392 20341 8163 32959″.

 

*SPOILER ALERT – ANSWER BELOW*


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Answer:

If you chose a, you were close. The answer is actually d – none of the above. This is because the ECMAScript standard does not define the interpretation of certain number literals, in particular number literals with a leading 0. Some JavaScript implementations will interpret these as integers with the leading 0 trimmed. Others will treat them as octal literals. It should be noted, though, that MOST JavaScript interpreters will perform the latter and interpret number literals with leading 0′s as octal literals. This is different from other languages, like Java’s Integer.parseInt(), which will conversely trim the leading 0.

So what actually gets printed? In most browsers, including IE 8, Firefox 3 and Chrome, the string “93021 16284 19 20341 32959″ gets printed (Notice the 19!). Let’s examine this step-by-step one more time…

  • 93021 – There is no leading 0, and so this number will get interpreted just as we expect, as the integer 93021, and so “93021″ will be written.
  • 16284 – Again, no leading 0, so no surprises here. “16284″ will be written.
  • 02392- This number has a leading 0, and so it will be interpreted as an octal literal. Notice, though, that the second least-significant-digit is a 9, which is not allowed in an octal number! And so, by the specification of parseInt(), it will read all digits until an illegal character is read. Therefore, parseInt() will parse the octal value 23, which equals ((2 x 8) + (3 * 1)) = (16 + 3) = 19 in decimal.
  • 20341 – This will return a number and it will be greater than 0, so “20341″ will be written.
  • 08163 – Again, this number has a leading 0. But, this time, the most-significant-digit is an 8, which is also not allowed in an octal number. So, parseInt() will interpret the octal value 0, and return 0. This fails the second part of our sanity check (that our ZIP-code must be non-zero), and so this doesn’t get printed!
  • 32959 – This will get printed as is. No surprise here either.

Moral:

Whenever possible, do not write an integer with a leading zero. Doing so can cause unexpected behaviour across browsers with different JavaScript implementations. If you can’t control the input values (as in our example above), then make use of parseInt()’s second optional parameter, radix – e.g. use parseInt(“08163″, 10) to parse “08163″ to a base-10 integer. Passing in the radix explicitly eliminates the variability between browser implementations.

That’s it for this JavaScript Puzzler! Until next time, happy coding!

Charles

javascript-puzzler-lets-print-some-zip-codes.zip (source code)

1:00 PM Comments (0) Permalink
November 23, 2010

Want to Localize Your Flex/AIR Apps? It’s Easy! I’ll Show You How!

If you have an application or a website, and you’re targeting (or want to be targeting) an international audience, then you’re going to have to localize!  What that means is preparing your application for international use by building support for multiple languages.  It may sound like a daunting task, but the Flex framework makes it surprisingly easy.  I’ve written a very simple tutorial on the Adobe Developer Connection Flex Community that walks through a straightforward way of localizing a basic Flex application.

Localization in Flex – Part 1: Compiling resources into an application

Here is the end-product of the tutorial, which you can easily create yourself, or implement within your own existing project!

This tutorial is only part 1 of the series, and illustrates one common way to achieve localization.  There is another different, but common, way, which I’ll illustrate in part 2, and I’ll announce on this blog as well :)

Until next time, happy coding!

Update: I’ve just completed Part 2. Read about it here :)

5:13 PM Comments (1) Permalink
November 10, 2010

WANTED: Computer Scientist Summer Intern!

Crazy awesome pic provided by eBoy.

Crazy awesome pic provided by eBoy

We’re hiring! I’m part of the Services Infrastructure team here at Adobe, and we’re looking for some bright and eager individuals to help us build some really cool things! This position is based out of the Adobe office in Seattle and for our team :D  Here’s the description…

Job Title:
Computer Scientist Summer Intern

Position Summary:
The Adobe Services Infrastructure Team is looking for exceptional people to work on systems software and tools in a creative, fun, and fast-paced environment. Join us and help build the core components of Adobe’s SaaS platform, the foundation for online products like photoshop.com and acrobat.com.

As a member of the team, you will work alongside the rest of the engineering staff. We’re a flexible team, and we will give you projects addressing a real-world need that will be put into service, while challenging your skills and providing you with practical work experience. We will work with you to set you up for success, starting small and building from there. Adobe has an end-of-summer Intern projects “expo” in a science-fair format where you present your work to Adobe staff (including hiring managers!). Plus, there will be a few fun things like an afternoon trip to the movies.

The following are examples of possible projects: write a tool that auto-generates release notes from check-in comments and bug database records, build an application for managing our wall of monitors reporting statistics on our various services, create a small AIR application that streams real-time statistics from our services to internal users’ desktops (like a stock ticker), or expand the functionality of our emergency phone dialer service.

This job requires a 3rd or 4th-year in a BS Computer Science or equivalent degree, work development experience, excellent verbal and written communication skills, some knowledge of or exposure to test automation frameworks, and preferably some experience developing Java applications and Flex/ActionScript/JavaScript client applications.

Requirements:
• Working towards BS or MS in Computer Science, or related technical discipline.
• Extensive experience with C/C++ and/or Java.
• Preferred experience building and maintaining software systems and/or services.
• A solid foundation and understanding in computer science with strong competencies in algorithms, data structures, and software design.

Contact:
E-mail me your resume and any other relevant materials you’d like to include at charlesb [at] adobe [dot] com.

For anyone that’s interested, I started off as an intern (with this team, in fact), and it’s a great way to gain some fantastic experience, work on cool projects with some great people, and just be part of an awesome company! I hope to hear from you!

Charles

6:28 PM Comments (10) Permalink
November 8, 2010

C Puzzler – Like Java Puzzlers, but for C!

I’m a big fan of Java Puzzlers. If you’re not familiar with what those are, I highly encourage you to watch this Google Tech Talk by Joshua Bloch. In short, Java Puzzlers are quirky pitfalls and corner-cases one might encounter when programming with the Java language. I liked the concept so much, I thought I’d add a section on my blog for my own puzzlers! The format is simple:

  1. Code – I introduce the code
  2. Question - I pose a multiple-choice question and you guess what the outcome is…think hard!
  3. Walkthrough - I walk through a reasonable explanation
  4. Answer - I tell you the real outcome (it might surprise you), and explain why
  5. Moral - How can we avoid making mistakes like this in our own code

Now that we know what a Puzzler is, here is a simple C Puzzler:

Code:

/** c-puzzler-lets-get-funcy.c **/
#include <stdio.h>
 
int funcOne();
int funcTwo();
 
int x = 1;
 
int main()
{
	int y = funcOne() + funcTwo();
 
	return y;
}
 
int funcOne()
{
	return x;
}
 
int funcTwo()
{
	return ++x;
}

Question:

What value does main return?

  1. 2
  2. 3
  3. 4
  4. it varies

Walkthrough:

There is a global variable, x, and it is initialized to 1. In main(), there is a local variable, y, and it is initialized to the value returned by funcOne() plus the value returned by funcTwo(). The function funcOne() simply returns the value stored in variable x, which is 1. The function funcTwo() also references x, but increments it in the process. Since the increment operator is a prefix, it performs the increment before returning the value, and so funcTwo() will return the incremented value of x, which is 2. Therefore, y will equal 1 + 2, which is 3, and main() will return the int value 3. So, my answer is b, main will return 3.

 

*SPOILER ALERT – ANSWER BELOW*


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Answer:

The answer is d – it varies. This is because in ANSI C, there is no guarantee as to the order in which the operands of an operator are evaluated. So, depending on the compiler implementation, funcOne() can be evaluated before funcTwo(), and vice versa, giving us a result of 3 or 4 depending on the compiler. It should be noted, though, that MOST C compilers will evaluate expressions of operands left to right, including the GNU compiler, but there is no guarantee that this is the case. As a result, the safest way to achieve compiler-agnostic results would be to use intermediary variables.

Moral:

The order in which operands of an operator is unspecified in C. So, to give safe and predictable results, external variables should be modified carefully, and specifically noted in the function’s documentation. If the documentation for a function is lacking, or you are working with a 3rd party API which, for all intents and purposes, is a black-box, use of intermediary variables to ensure order of operations is safest.

I hope you’ve enjoyed my first C Puzzler! Until next time, happy coding!

Charles

c-puzzler-lets-get-funcy.zip (source code)

1:30 PM Comments (2) Permalink
May 20, 2010

I’ll trade you…a joke for a book

My name is Charles and this is my blog.

So, I’ve decided to start an official blog on Adobe Blogs.  Since I graduated (and even while in university), I’ve tried to contribute to the community as much as I could, but lately, I’ve been…well…lazy.  This blog is my attempt at getting back at it, for better or for worse : P

I thought, what should my first (really second) post be about?  I figured it should be something engaging, like asking people to guess approximately how many lines of code there are in CS5 (which we just recently released), or asking people to submit some ActionScript code to do something like sort a list of 10,000 numbers, most efficient gets a prize.  But, I thought that these are kinda cliché and kinda boring…let’s do something fun.

How about this:

Add a comment to this post with your favorite tech joke.  On June 4th, 2010 (two weeks from today), myself and an impartial jury (i.e. my team-mates) will choose the best ones, and I’ll send you a book!

books.jpgI have a bunch of books ready to ship out, mostly about Flash, Flex, AIR, and ActionScript, but I obviously can’t give one to everyone.  So, top 5 will definitely get something, and, if shipping isn’t killing me, runners up will get consolation prizes!  That’s it!

Happy commenting!

*Important: Make sure you put a valid e-mail address so that I can contact you if you’re a winner!

*Update: There were only 7 entries, so you ALL get a book : )  For anyone reading this post after today, feel free to add more…these are GREAT!
2:44 AM Comments (15) Permalink
April 20, 2010

Hello, Interwebs!

Hello, Interwebs.  My name is Charles.

2:30 PM Comments (1) Permalink