Cooking With Joy Daryl Ducharme Cooking With Joy Daryl Ducharme

Resolution 2013:Cooking With Joy - first update

Me with my first 2013 resolution mealMy 2013 New Year's resolution is cooking with joy. This was all brought on when I bought the book "The 4-Hour Chef" by Tim Ferriss. I discuss how the resolution came to be and how it is going in the beginning of 2013. Along the way I give reviews on the recipes I've done to date in the book. Did I succeed? Did I fail? Have I already given up?

Me with my first 2013 resolution mealMy main resolution for 2013 is cooking with joy. I have cooked a lot and I used to cook with joy before the kids made it hard to be very creative in the kitchen. Now that they are old enough I can take on cooking again.

The genesis of the idea to take on cooking with joy as my 2013 resolution was the book, The 4-Hour Chef by Tim Ferriss. I got the book after listening to an interview with Tim Ferriss on The New Man Podcast. In the interview Tim mentioned that the book was a book about how to get great at anything fast but using cooking, and his applying methodologies to learning to cook, as the vehicle for this information. Because of this my updates that link in my work from this book will also be a piece-meal review of the sections of the book I reference for my own resolution.

Pre-Resolution

After I listened to the interview, I went online and found out that The 4-Hour Chef was available on Kindle for the sale price of $4.99. As of this writing it is $9.99. At $5, it was most assuredly worth it. At $10, your mileage may vary. The book did inspire me for my resolution, and so far I have had success (more on that shortly), but there are some hiccups along the way.

I got this book at the end of November and I started reading it then. The first section, entitled "Meta" is really the meat of the get great at anything fast information. The DS3 and CaFE methodology makes sense but you don't hear much about it (at least directly) after this section. The actual cooking, and a great place to start if you only care about the cooking, is in the second section "The Domestic." I held off on being "The Domestic" until the new year, because Christmas was coming and I thought to put some of the better kitchen items recommended on my wish list. It worked for my initial needs. Since the beginning of the year I've been working my way, slowly, through the topics and recipes. Using what I learn or am attempting to learn to make dinner for my family each Sunday. Here's how the lessons and meals have gone for me so far.

First Recipe/First Dinner - Osso "Buko"

This recipe was an easy win and claimed to teach braising and blade grip. I was worried that I would buy expensive lamb shanks and only my wife and I would like the meal (the main reason I stopped cooking when the kids were younger). However, both my kids loved the meal. My 9 year old has a thing for eating meat from the bone right now so it was right up his alley. My 6 year told me it was tasty.

As this was the first thing in the book and it was a main dish, I used the carrots that are cooked with it as the vegetable and had some rice and leftover bread for the starch. The carrots were okay, they were basically stewed carrots. So if you like that you'll be fine. My kids were less than impressed and I've never been a fan of stewed carrots so - meh. I might try it without the carrots in the future and pick a vegetable that will contrast with the entree more.

Other notes from my first meal

I used a pan-saver type bag with my dutch oven and it did make cleanup easy. This was especially nice since my wife wanted to use the juices in a broth she was making. However, I have yet to try without the pan savers so I don't know if overall cleanup without bags is really that bad. How to hold your blade was taught along with the direction to cut the ends of the carrots. This is a nice and easy introduction as opposed to something deeper. More knife handling techniques are taught later as necessary. Part of me likes this low-stakes approach to learning to cook but the other part of me feels a little cheated. However, he did just say blade grip so I did learn what he said I would.

One editing note about the kindle edition of this book. It seems step 3 is not written down in the recipe and I did things out of order. If you look at the A, B, C picture and realize that step 3 is related to picture C you'll be a-okay. It didn't seem to affect the meal though so no big deal. I was just wondering why I had bought a big can of whole tomatoes for a second.

Second Recipe - Scrambled Eggs

Scrambled eggs are a very neutral food and as such are used to teach flavor combinations. This recipe is actually ongoing. So far I've tried the first two flavor combinations for North East African and Middle East flavorings. I've also tried different ratios of egg whites to egg yolks. My initial thoughts on the white to yolk ratio is that, it isn't a big deal. I can notice a difference, but if I'm cooking for myself I'm not going to waste any of the egg parts. However, he does make a point to give options for how to use leftover egg whites. As for the flavor combinations I'm learning that you don't want to be timid with the flavoring. At this point he talks about a 3 finger pinch and eyeballing the amounts. You can go more and learn to back off if it is too much. Right now you are learning flavors. A little bonus for me today, Safeway had all the spices BOGO so I bought a bunch that I wasn't planning on so I hope to learn some new flavor combinations I can add to other recipes. I've already applied the North East African (mint, cumin, garlic) to a sauce I was making - that's when I learned I can use more. By the way, the snotty texture he recommends making are absolutely stellar. I did, surprisingly, improve my ability to make a basic like scrambled eggs.

Third Recipe/Second Dinner - Coconut Cauliflower Curry Mash

This alliteratively named dish is aimed at teaching the skill of Mash Anything and I must admit I was skeptical. I had read the recipe so many times and I didn't feel like I would have the sense that I could mash anything after all was said and done. Turns out, I did feel like I could do it. After I finished I went back to the book and read the sidebar section titled, "Mashing Variations" and I think I'll try them out in future dinners. The kids didn't really dig the cauliflower mash, though one did say he though it tasted good. Or, was that "interesting?" Of course, they don't usually like cauliflower anyway so I wasn't expecting much. It was an unexpected texture and flavor combination and it was very filling. Because it was a side dish I had to come up with a main dish. For the main dish I did the bonus points recipe from Osso "Buko" which was named Jude's Chuck Roast. I braised again and it turned out amazing. I used 10oz cans of the broth, consommé and soup which was plenty for braising in the dutch oven. For extra bonus points I used the cipollini onions, a very good idea.

Overall I'd say the recipe was good, even if not a hit with the kids. The chuck roast was a hit with the kids though so I did have a win with the dinner. In the introduction to the recipe he does mention the C3 mash as a good alternative when you need a snack. I think it would be, it was surprisingly filling and tasted good. Another editing note on the kindle edition for this recipe as well. He says you need a dutch oven for the recipe but I don't think that is necessary. For one, the pictures in the book don't match him using a dutch oven. For the other, I was using the dutch oven for my meat dish in the oven already so I just used a regular pot and it turned out fine. On a personal note, I thought there wasn't enough liquid in the mash when I was suppose to get it boiling so I put the whole can of coconut milk in - this wasn't necessary. In the end I had to do a mixture of draining the pot and cooking the excess liquid off to get it to a thicker consistency.

First update conclusions

So far, so good with the resolution. I've been happy and successful working at the pace I am with the stakes that I've set. The book may be written in a weird, jockish, frat boy voice (on purpose) and may have some editing problems but it seems to deliver on what it claims with regards to cooking. As for the get great at anything fast business, we'll see. Also, I've read through the entire "The Domestic" section along with the section titled "The Wild" and only just began the section titled "The Scientist." I'm not sure how much if any I'll do beyond "The Domestic", especially the part about pigeons, but we'll see and I'll update here.

Speaking of updates, I've already noticed and mentioned some editing issues with the kindle edition of the book. I don't know if these affect the hardcover edition. However, since I am talking about the Kindle edition I hope some edits can be made and the book can be updated for myself and future readers. This is one of the benefits of Kindle books that is underutilized in my opinion.

Read More
Coding and Development Daryl Ducharme Coding and Development Daryl Ducharme

Ignoring file changes with git

Here's a quick little post about one of the most useful tricks you can do with git. Often you have files you are working with in a project that you need to track the file for everyone on the project to have but not save your changes to the file itself. For example, project files in eclipse that change how the project uses the files. To have the file in the index but not save the changes, do the following.

  1. do a
    git add 
  2. do a
    git commit
  3. do a
    git update-index --assume-unchanged [FilePath]

Now the file you have told git that any changes you make to the file, it can ignore. There are a couple more notes you might want to know.

  • To stop ignoring changes to the file you can call git update-index --no-assume-unchanged
  • If someone else changes the file in a merge, even if they change it back, you'll have to tell git to ignore it again.
  • Egit, the eclipse git plugin, has this functionality under the advanced section of the team menu.
  • Rebasing always seems to require me to remind git to ignore changes.

This has been a great help for files at work. Actionscript project files like .actionscriptproperties, .project and a developer config file are important to have tracked but helpful to allow untracked changes.

Read More
Geekiness, Randomness Daryl Ducharme Geekiness, Randomness Daryl Ducharme

Social Network Conundrum

What does one do with all the social networks? I'm not sure but in an effort to organize my online social life I wanted to create rules for myself around what social networks and this blog will be used for.

What does one do with all the social networks? I'm not sure but in an effort to organize my online social life I wanted to create rules for myself around what social networks and this blog will be used for. Consider this an experiment. What falls away will fall away, everything else can stay.

Below are the ways I think of each social network and what I plan to post there.

Facebook

Main online presence where I will share most things I want my friends and acquaintances to see.

  • Videos
  • My upcoming events - I am an active guy
  • Thoughts

Twitter

Another major online presence but a great place for just random short thoughts

  • Bad jokes
  • Programmer thoughts - most of my friends on facebook don't really don't speak gobbledygook
  • Events as they happen
  • Psuedo-conversations with fellow twitter users.

YouTube

  • Videos I take
  • Hangouts - I have some ideas for themed ones.
  • Videos saved from ustream

Google Plus

I like G+ still but it is so hard to post. I'm just going to turn it into the place to post stuff that is easy to post there. Turns out this is mostly Google related links.

Tumblr

I don't put much content here but if I do it will be.

  • Stupid photos
  • Longer random thoughts that only people who really opted in will want to see. By longer random thoughts I mean longer than the 140 character limit of twitter but not deserving of a full blog post.

UStream

  • This is the place for behind the scenes video of my life.
  • There is a possibility I could start JAMM live broadcasts again in the future.

Pinterest

I must admit, this one is dying quick. I haven't

  • Silly pictures
  • Memorable videos

What about this blog?

Articles that well thought out will go in this blog. I want to write better so I will do my best. However, I have been wanting to write a lot more and trying to be to clean and neat usually keeps me from writing so please bear with me as I get better at first and second drafts.

Conclusion

There are too many social networks but being an inhabitant and creator within the social space I feel it is necessary to check them out and see what works. What works for you? I know my list is small. Should I be trying something else? Is there something else a reader of my blog would like to see me use one of these services for? I'm open to ideas and comments. Thanks for reading.

Read More
Coding and Development, Humor Daryl Ducharme Coding and Development, Humor Daryl Ducharme

Cascading Sarcasm Sheets

CSSI love the organization of the semantic web. Instead of grouping things as they should look, group items as they make sense semantically then change how they look with cascading style sheets. This works great with paragraphs, ordered and unordered lists of different things, and to a lesser part using divs and/or spans for different sections of data. Still, with all this we haven't come up with a real good way of semantically marking up sarcasm, hyperbole, intended puns, unintended puns and more verbal word play that is best delivered via body language and intonation.

What originally got me thinking all this was sarcasm doesn't do well on the internet but people try to use it all the time. Maybe it's just me, and the people I know, but it is often denoted with sarcasm HTML tags (<sarcasm>yeah, sure!</sarcasm>). I had been thinking about this on my own for some time so I decided to discuss this with my mentor at work. He thought about it for a bit and said to me, "That seems inefficient. You should only markup things that aren't sarcastic. How about a serious tag?(<serious>I'll take 2</serious>)" Being pragmatic I thought, really there are both then everything in between. He agreed.

Next we discussed how we needed to do the levels of sarcasm and seriousness in a span of text. You may want to do something special to css that is really sarcastic or deathly serious. My response was that you could just use class attributes to help you mark up your code. The other option is to wrap a sarcasm tag with an emphasis or strong tags to denote regular, mild and strong cases of each.

<sarcasm>I'm sure you're right</sarcasm>
<em><sarcasm>You sure know what you are talking about</sarcasm></em>
<strong><sarcasm>You are a genius!</sarcasm></strong>

Whether using class attributes or extra tags you can use CSS to change all the various combinations and in between states. It all depends upon which order you place them in your style sheet. Sounds like fun, as long as I don't have a deadline.

Now, I haven't had any time to code up a semantic site rife with sarcasm tags but there might be some out there. If you've got a site or know of one that uses sarcasm tags or anything similar then uses some awesome CSS to showcase it, I'd love to see it and share. Let me know all about it in the comments section, down below.

Read More
Randomness Daryl Ducharme Randomness Daryl Ducharme

What to write, what to write

It has been a while since I have written in my blog. How many of my blog posts start with this or something similar? It's not like I don't have anything to write. Here is a look at why I think I might not have been adding to my blog.

It has been a while since I have written in my blog. How many of my blog posts start with this or something similar? It's not like I don't have anything to write. I'm up at night all the time because my mind is racing. Here are some of the things that keep me up at night pondering and that I have plenty to write about:

  • Male/Female interactions - gender studies
  • Attempting to learn French
  • Magic
  • Programming
  • Raising Kids
  • Being a husband
  • Identity
  • Improv
  • Wrestling
  • Stand-up
  • Random cool stuff I want to learn or am pondering
  • Cool people I have in my life
  • Politics

So if I have all this stuff to write, why haven't I? I have a few theories that might be why I have blog writers block.

I'm keeping myself quite busy

While this is true, I have quite a busy life, I have also been spending a lot of time at home doing what amounts to very little. In order to increase my nerd cred I've started watching Doctor Who. I have spent many nights watching 2-3 episodes over the past few weeks. I guess I could reduce that to one. Then there is always the dreaded Facebook refreshing. Even though there isn't much there I keep thinking I'll get a notification any time now. So if I'm not keeping myself so busy that there is not extra time, what else is there?

I've limited my blog

A couple years back, in an attempt to get myself to write more I created a schedule for my blog. This spawned Just Another Magic Monday, Wednesday Warrior, Flash Friday and Sunday Funnies posts. At first, this worked. Then I stopped. Perhaps I don't want a specific schedule, perhaps I just need a check in. There are no hard and fast rules saying I can't post whatever and whenever I want so once again I have an excuse without weight. Any other stops?

Social media makes posting easier somewhere else

I am definitely an oversharer on Facebook and other social networks. I think this is part of the reason I have a Klout score that currently ranks around 60. The fact that I even know that is a sign. It is easy though. Take someone else's content and just share it. Maybe I can add a one sentence opinion. This works but it still leaves my mind full of more flushed out thoughts and opinions that need to be refined and written down so as not to keep me up at nights. In fact, I think it even adds to my list. Especially during a presidential election year such as this.

What now?

I've pinpointed some beliefs that might be keeping me from writing. How can I use this knowledge to write. I can most assuredly only watch a single of Doctor Who (or any television show) to one episode a night. I'm a smart enough individual to know that those Facebook notifications are at least 50% game notifications and can wait until the next day. Nothing too pressing there. There are no hard and fast rules on my blog so I should work towards a schedule of writing anything once or twice a week rather than a schedule of writing something specific that never gets done. As for social media, I need to realize that is a consumption and sharing setup and doesn't really fulfill my creative needs.

It is time to write! Now, what to write?

Read More
Improv, Randomness Daryl Ducharme Improv, Randomness Daryl Ducharme

My 'Journal' Entry

A postcard for 'The Journal' and a white russian.Here I am, with less than a week until my first performance in a long form improvisational comedy show. The show I'm in is called [The Journal][] and parodies the tragic romances of [Nicholas Sparks][]. I've had a weird experience with this show so I thought I would share it.

A postcard for 'The Journal' and a white russian.Here I am, with less than a week until my first performance in a long form improvisational comedy show. The show I'm in is called The Journal and parodies the tragic romances of Nicholas Sparks. I've had a weird experience with this show so I thought I would share it.

Warning: Logic does not apply

My experience with The Journal is based in my subconscious and the inner workings of my brain working against me. It is easy to apply logic and wonder why I had any issues. Shush! Logic does not apply here! Though it did finally lead me to the proper solution I was not being conscious of the way my emotions were leading me around.

Finding out about The Journal

Since moving back to Seattle I had decided to really focus on performing improv, rather than just taking classes, a reality. This led me to auditioning for Jet City Improv and ComedySportz Seattle. I had a lot of fun at the auditions but I didn't even make callbacks for either. I talked a positive game afterward but, especially for ComedySportz Seattle I felt really bummed. I learned my improv chops through ComedySportz San Jose and really wanted to be a part of it here in Seattle.

Near the end of my Long Form Essentials class that I was taking through Jet City Improv, our teacher Mandy, sent out an email telling us all about upcoming auditions for The Journal. Also, she sent me a follow up email telling me that she put in a good word about me with the producer. This made me feel good because I think she is an awesome improviser who's style I'd like to emulate in many ways. So I was riding high knowing I had made an impression with someone who I respect. That is, I was riding high until auditions.

Auditions

For Jet City Improv and ComedySportz Seattle auditions I felt that I had done pretty good. I had a feeling I wouldn't make the cut but I still felt I had done well overall. For the first audition to The Journal I had actually studied Nicholas Sparks movies and even watched The Notebook right before the audition. It seemed like a more serious piece so I was doing the serious thing of studying (something I never did much before). After the first audition I went home thinking I was in over my head. I felt some of the other improvisers did much better at long form theatrical improv and I had no chance.

To my surprise, I got called back! That good word from Mandy must've paid off, either that or they could tell, and appreciated, that I had recently watched The Notebook. In my mind, "Thank You Mandy!" There was no way I had made the difference there. I was there and I felt I had done a really poor job.

NOTE: Logic doesn't really pertain here, as I said above, but logic says that when you do an audition you have no idea what the people running the auditions are looking for so do your best and then don't worry about it

At the callbacks I realized only 1 or 2 others got called back and the rest of the people there knew each other from Seattle Experimental Theater's (SET) previous show Where No Man Has Gone Before. I had an inkling of feeling special but then I saw the people work together who knew each other. They were really connected with each other and were funny without even trying. I left that audition feeling worse about my performance than the last time, but hey - at least I made it to callbacks this time.

NOTE: If you've never done improv, you may not know that knowing your fellow improvisers helps so, so much.

Funny thing about how I felt about my performance, it didn't matter. They offered me a part in the show! Thanks again Mandy! I obviously had nothing to do with it.

First Rehearsals

So off to rehearsals I went and this is when stuff really got weird for me. I didn't act like my improv self at all. I'll explain by going back in time to my educations at ComedySportz San Jose. I once asked my improv teacher Michael, what he thought I needed to work on to be a better improviser. For the most part, he said I had good instincts and I was never afraid to jump on stage first and try out an idea. The main thing he said I should work on is letting others take the spotlight and learn how to add to their ideas. Jumping back to rehearsals for The Journal, I was definitely attempting to practice giving others the spotlight but now I was timid and afraid of my ideas.

Things all came to a head one day when I was called in early by myself to work on my breathing while talking. Before I got there I was walking with the producer and explaining to her how I was getting something out of being in The Journal because I usually just jump on to stage and don't do as much support. Her responses, "I really don't see that from you". Also, I did the breathing exercises with the Stage Manager and she realized that I was having the problems when I was second guessing myself. A mini lightbulb went off in my head at that point but I was still timid for the rest of that rehearsal. It was later that evening that I did some brooding (my form of soul searching I think) and came to some powerful realizations.

The realizations

The first thing I realized was that I put a lot of pressure on myself because I didn't want to let down Mandy who had stood up for my talents. I felt that if I did poorly, I wouldn't just let her down but make her lose credibility as well.

It was then that I remembered something she said in class that I never thought I would need to do myself. She said that when she performs she actually gives herself permission to mess up. I took it a step further and decided to take a bigger risk and have since been saying to myself, "I give myself permission to fuck things up!" Funny thing about improv when you trust your fellow improvisers on stage, you can not break a scene no matter how hard you try.

I also realized something I have been hinting at a bit in this article, I was not giving myself enough credit. The rest of the cast were pretty much set before auditions even happened as they all knew each other from before. However, they asked me to join them and be a part of their show. They had other talented people try out but they chose me. Whatever the reason, they felt I would be an asset to the show and yet there I was acting like I didn't deserve to be there. No more! I bring a certain energy to the table.

Finally, looking back at my previous auditions for Jet City Improv and ComedySportz Seattle I realized that I hadn't given myself explicit permission to make any mistakes. Perhaps next time I audition for either I will give myself that permission and see if it helps. I may not make it (there are some amazing improvisers in Seattle) but at least I'll feel that I put it all out there at an audition.

Now on to the show

I've only had a few rehearsals since the revelations, but I have felt so much better about each of them. The first day I was still a bit timid but I kept reminding myself that I give myself permission to fuck things up. Not only have I felt that I have performed better, but I have had more fun and been more connected with the rest of the cast. I'm not completely over the illogical self deprecating thoughts that are in my head, but by being conscious of them I can make choices without listening to them.

Only 2 more rehearsals until a dress rehearsal in front of an audience and then it is opening night. We've got 4 shows and I can't wait to see what the audience brings each time. I know we are going to do great with whatever we are given.

Conclusion

I was thinking of holding off writing this until after the show, but I don't see why I should. I can't break the show, there are too many talented people working on it. I just hope that some other entertainer will read these words and get some insight for themselves. At the minimum, I will read it some day in the future and be reminded that I have permission to be bold.

Read More
Wednesday Warrior Daryl Ducharme Wednesday Warrior Daryl Ducharme

What are we doing?

With this past week's tragedy in Aurora, CO there are lots of different discussions. What concerns me more and more every time I see this sort of thing is, "What are we doing that has our young men turning into mass murderers?"

Batman mourns theater shootingWith this past week's tragedy in Aurora, CO there are lots of different discussions about guns. Some people are saying we should implement gun control while others are saying that if more people in the theater had weapons to defend themselves there would have been less loss of life. Opinions are rampant, facts and data are elusive, so I won't be discussing that. Actually, what concerns me more and more every time I see this sort of thing is, "What are we doing that has our young men turning into mass murderers?"

That is the uncomfortable question. With a tragedy where one person causes all the carnage, it is easy to point the blame at that individual and wipe our hands of it. If this only happened once a generation, perhaps that would be okay. However, this type of lone gunman with no logical reason event seems to be happening more often (please correct me if my emotional numbers don't match the real numbers) than before. In fact, this current tragedy bookends with the much earlier Columbine shootings in the same area. It's about time we look at ourselves, as individuals, as communities and as a society at large about what our responsibility in these events is.

Responsibility (not blame)

Notice I said responsibility and not blame. People often collapse these two terms together and have them mean the same thing. For the purposes of this article I want to distinguish that blame is allocation of fault while responsibility is being cause in the matter. Our responsibility in these tragedies should be to learn from them and find out why they happened. Is it guns? Is it mental health care? Is it bullying? Is it parenting? Is it video games? Is it the fact that the air is thinner in Colorado? It is easy to get defensive when these questions get asked, who wants to be at fault for any of this? That is why I bring up responsibility, you may not want to be at fault but hopefully you want to be able to make a difference. By seeing where you (and I am using the plural you that English lacks along with the singular you) were cause in the matter you have the opportunity to make a difference in the future.

Conclusion

For myself I see a certain disconnectedness with the rest of the people around me. I ride the bus at all manners of the night and day. I see lots of lonely, lots of crazy, lots of belligerent and I tend to ignore it with the hope that it will just go away. It seems to when they get off the bus, or when I do, but it didn't go away it just moved to another place. I don't know how I should react or what I should do but perhaps me being conscious of the connectedness of all these people in our lives could start me down the path. Heck, it might even make a difference with one person. I'd probably never know but perhaps I don't need to. Perhaps that's another way I'm responsible, only taking actions when I know the results rather than having a little faith in the difference I can make. It's a thought I'll keep pondering.

What are your thoughts? Have you seen other discussions about the tough questions we should be asking ourselves after these tragedies? Let me know about them in the comments.

[youtube http://www.youtube.com/watch?v=PivWY9wn5ps&w=480&h=360]

Read More
Flash Friday Daryl Ducharme Flash Friday Daryl Ducharme

Repeated string without a loop

ascodeicon.png

A problem comes up

This week I had a relatively simple problem that I needed to solve. Because it was simple and I didn't like the obvious solution, I thought I'd share the solution I came up with.

The problem was this:

  • I had a string where each character represented some data as part of a collection of data.
  • I had to change these characters out of order (for example: character 196, then 13, then 87, etc)

My approach - Create a string of n-length

The approach I decided on was to start by creating a string of the final length I would need then update each character as I got the information I needed. Should be simple enough to create a string of a certain length but alas, not so simple as to have a String.createStringOfLength() method.

The obvious method

My first method of doing this is the obvious loop method. I'm a big fan of loops so it looked like this:

function createStringOfLength(length:uint):String {
    // we'll use 'x' as our default character - spaces are fine too.
    var output:String = "";
    for(var index:uint = 0; index < length; index++){
         output += "x";
    }
    return output;
}

And that function works fine, it is understandable but it just seems that there should be a more elegant solution.

A more elegant solution

The problem with the method above is that I can't just create a string of an arbitrary length but I feel like I should be able to. Is there something else in AS3 that you can create of an arbitrary length? Yes! You can create a Vector of a specific length and use default values to boot.

Here's where it starts to get elegant. Since Strings really are just an array of characters this correlation makes a lot of sense. The code above can actually be recreated in 2 lines (not counting the function definition and enclosing curly braces).

function createStringOfLength(length:uint):String {
     var output:Vector.<uint> = new Vector.<uint>(count, true);
     return output.join("").replace(/0/g, "x");
}

I used a few tricks of the language here, so some of this may not be obvious. First, in AS3, the default value for a uint is 0. That is the reason I search for it in the pattern for the replace call. Second, and really the main thing, I took advantage of the ability to create a Vector of a specified length and fill it with its type (in this case uint) defaults. Finally, I just used the Vector.join method and replaced the default 0 with whatever character I wanted. Admittedly, I could have just left them all as 0 but the replace step was so simple I thought I'd throw it in.

Conclusion

There probably wasn't a performance reason for me to create this solution, and I honestly don't know if it is any more performant. Looking at new ways to relate to a problem is the bread and butter of a programmer though. So, if you've ever wanted to create a string of a specified length or repeat any string a certain number of times here is a new way to think about the problem.

Do you have another solution? If so, I'd love to hear it. Did you like my solution? Hate it? Have an improvement? Let me know in the comments below or share a link to your code. Github's gists are a great way to share code snippets - as I just did right there.

Read More
Flash Friday Daryl Ducharme Flash Friday Daryl Ducharme

Function Overloading in AS3

Why doesn't AS3 have function overloading

If there is anything I hate more than when actionscript doesn't do something I wish it would, it is when people complain about something they wish it would do. Sure, it would be nice if it incorporated every programming concept ever but that just isn't going to happen. In fact, this point is the same for every language out there. It sure would be nice if they all did everything but then there would only be syntacticular differences and that would be silly. Anyway, actionscript does not natively offer function overloading, and I've heard and/or read people complain about that from time to time.

Roll your own

Usually the reason you wish a solution existed natively is because you've used it before and you'd like to have the same ease writing the code. At least, if we follow the premise of not pre-optimizing code. So, if a language doesn't have that construct what do you do? Either find an alternate or roll your own. Today we are going to roll our own method for overloading functions in AS3 to allow for some of the benifits of native function overloading.

This isn't my idea

I have to admit, this isn't my idea. Back in the days of AS2, there was one library that did a lot of rolling its own solutions to constructs actionscript didn't provide. That library was as2lib by Simon Wacker and Martin Heidegger. I remember just reading the as2lib source code to learn different ways of doing thing. They had a solution for function overloading that I used as a basis for the AS3 code. I figured, AS3 had better reflection and introspection (as2lib had libraries for that as well) than AS2 so this should be fairly easy. In some ways it was and in some was it wasn't. That's a good thing because I learned a few things along the way.

Enough typing, where's the code

The code I wrote to allow this functionality is available at github. Usual rules apply, this code is just a proof of concept, for educational purposes only. Though I've written some tests, I make no guarantees.

Sample Usage

Sample usage is available in the Main.as file on github but I'll provide you with a taste here.

private function aFunction(... args):* {
    const overloader:Overloader = new Overloader();
    overloader.addHandler([String, Number], onStringNumber);
    overloader.addHandler([String], onString);
    overloader.addHandler([Number], onNumber);
    overloader.addHandler([int], onInt);
    overloader.addHandler([uint], onUint);
    overloader.addHandler([Boolean], onBoolean);
    return overloader.process(args);
}

private function onInt(value:int):void {
    trace("We got int: " + value);
}

private function onUint(value:uint):void {
    trace("We got uint: " + value);
}

private function onBoolean(value:Boolean):void {
    trace("We got Boolean: " + value);
}

private function onNumber(num:Number):void {
    trace("We got number: " + num);
}

private function onString(str:String):void {
    trace("We got string: " + str);
}

private function onStringNumber(str:String, num:Number):void {
    trace("We got string, number: " + str + ", " + num);
}

// then to use the overloaded function
public funciton Main(){
    aFunction("Hello World", 13); // output: We got string, number: Hello World, 13
    aFunction(1 == 0); // output: We got Boolean: false
    aFunction(13); // output: We got uint: 13
    aFunction("Goodbye"); // output: We got string: Goodbye
}

A couple notes and gotchas that you might be wondering about as you look at this code.

  • Numerical arguments are automatically converted to any numerical class asked for, as long as the value can be of that type.

    • For this reason I made it test numerical explicitness in the following order: uint before int and int before Number.

      • Therefore if their are two matching functions due to numerical parameters a method using uint will be considered more explicit than a method using int or number.
    • You can't force a numerical type. I tried several methods and none worked.
  • If your overloaded function returns void you will need it to return * so it will compile without error.
    • EDIT: not true, just don't use a return statement
  • Because AS3 uses method closures most of the time, instead of anonymous functions, you usually don't have to worry about function scope. This is mostly a good thing. Watch out if you do use an anonymous function though. It will most likely work correct but there are a few ways it could fool you.
  • I wanted to do introspection on the method signatures so you didn't have to send in the values but, alas, method signatures do not seem to be available via reflection. From what I could figure out from studying the Tamarin code, they are part of the functions Trait object which isn't available from actionscript (and may go away in the future according to the documentation). This means you have to put them in as Arrays.

Not True Overloading

Okay, so this isn't true overloading but it gets us a little of the way there. The only solutions available online use the ellipsis (...) method but you still have to write the boilerplate logic to provide type checking. Also, what happens if there is no match? With my code you at least get an error telling you what went wrong. It isn't compile time but it can help with debugging.

Also, look at what this solution actually provides. It doesn't have to be used for function overloading. It could be used anywhere you want to handle differing types of data passed in as arguments. I could envision this helping to trim down some nasty if and/or switch statements. Take a look and see what it could do for you.

Conclusion

I find the Function class and Function objects fascinating in actionscript. Back when I dug into the different types of Delegate classes for AS2 (I actually made a similar one for AS3 at one time) I learned a lot about the language as a whole. Scope used to be the bane of my existence and then I finally understood it. Scope may not be an issue anymore in AS3 but there is still quite a bit to learned about the language from studying Function objects. The very fact that a Function is an object that can be passed around in actionscript is a very nice thing. Not all languages allow that type of functionality. I guess if you are using those, you'll have to roll your own function passing solution.

Read More