Programming Posts

8 Dart Features Those Fat Cats Don’t Want You to Know

Productive code without ceremony

In this article, I’ll show you eight more features that help Dart stand on its own as a productive, ceremony-free language. Remember, Dart compiles to JavaScript, so everything you see here works across the modern Web.

Dart makes fluent APIs easy

Libraries like jQuery have popularized a fluent design that encourages chaining calls for easier-to-read code. Dart takes a cue from Smalltalk and adds method cascades to the language, so that any API can be used in a fluent style.

Without cascades, the variable button is repeated for every method call.

// Without cascades.
var button = new ButtonElement();
button.id = 'awesome';
button.classes.add('important');
button.onClick.listen((e) => beAwesome());
button.text = 'Click Me!';

Use cascades to help reduce repetition.

// With cascades.
var button = new ButtonElement()
  ..id = 'awesome'
  ..classes.add('important')
  ..onClick.listen((e) => beAwesome())
  ..text = 'Click Me!';

Read more…

Comment |

Thinking in Code

Multithreading for your brain

Allen Downey, is a Professor of Computer Science at Olin College of Engineering. He has written three books for us, so far, Think Python, Think Stats, and Think Complexity. I recently got the chance to sit down with him to talk about how writing good code can and should actually change the way you think—and make you a better programmer.

  • Think differently when dealing with natural language, math, and code [Discussed at 0:38]
  • Better code equals a better brain [Discussed at 2:05]
  • Look to Python for a jumpstart [Discussed at 4:43]
  • Manage the complexity of code for long lasting programs [Discussed at 7:12]
  • Dealing with legacy programs? Try to see the big picture. [Discussed at 8:40]

You can view the entire interview in the following video.

Read more…

Comment |

Driving the Momentum of Modern Web App Development

Ido Green on modern web app design considerations and characteristics of great web apps

The rapid pace of improvements in browser technologies and the growith of HTML5 have presented many opportunities and challenges for web app developers. In the following interview, Ido Green, developer advocate for Google Chrome OS, reviews some characteristics of the “modern” web app and covers a few design points and helpful tools developers should keep in mind. Green will expand on these ideas in an upcoming free webcast, “Modern Web Applications Utilizing HTML5 APIs,” on Thursday, May 30 at 10 a.m. PT.

What is a “modern” web app?

ido_green

Ido Green

Ido Green: A “modern” web app is an application that utilizes HTML5 APIs and browser technologies to let the users accomplish a certain goal.

In most of the “great” web applications we see several characteristics:

  • They are self contained (maybe from here we got the term “one page application”) with one main goal.
  • They feel “native”: they are leveraging HTML5 APIs that let the app have “native” capabilities, like Offline, Geo, drag and drop, transitions, etc.
  • They are “offline first,” since we wish our users to be productive when there is no connection or when there is a flaky connection. These apps are built from the ground up with the idea of “offline.” It’s similar to a native app that you will “install” first and later fetch the data.
  • They are device aware: the apps are working great on mobile devices as well as on laptops and desktops.
  • They offer great performance: the great modern apps are utilizing CSS3, HTML5 and the mobile browsers to give the users a smooth experience where everything is working fast. The “offline first” methodology is helping here as well.

Read more…

Comment |

A Commencement Speech for Graduating 2013 CS Majors

Passion isn't just for romance novels.

Graduates, parents, guests, members of the faculty of <%= college.collegeName %>. I am honored today to have the opportunity to speak with you, as you move out of the cloistered environment of higher education, and into “the real world.” Except for those of you moving on to postgraduate degrees, of course. You will get to enjoy a life uncluttered by 401Ks and team building exercises for a few more blessed years.

But, for the rest of you, today marks your first step into a journey that will last the rest of your life, unless you’re able to cash in on your equity in some startup, in which case I’m sure you’ll be hearing from the
<%= college.collegeName %> alumni office before the check settles from your brokerage.

In my 35 years of experience in the software field, I’ve met a lot of developers, young and old. And the one thing that separated the truly successful ones from the crowd is passion. Now passion is an overused and abused term these days. Too often people take it to mean a passion for being successful, for achieving a personal goal in their life. When I talk about passion, I mean love. I’ve been in love with computers since I was 14 years old, and I’d be playing with them even if I didn’t get paid for it. If software engineering is merely a means to an end, you’re not going to be happy in the long term working in this field, because much of it is God-awful boring unless you have a passion for it.

Being passionate about software is critical to being successful, because the field is a constantly moving target. What will net you $130K today will be done by junior programmers in five years, and unless you’re constantly adding new tools to your belt, you’re going to find yourself priced out of the market. Many of the best projects I’ve ever worked on came to me because I had already gained the skill-set on my own. Play around with new technologies, contribute to open source projects, and you may find yourself with an opportunity to apply those skills on the job, and get them into your resume. You are rarely going to get an opportunity to have your current employer pay for you to learn things, so learn them on your own and be in a position to leverage the skills when a new project comes along. But if you have a passion for technology, you’ll already be doing it, and enjoying it without needing me to tell you to. That’s why passionate people have a leg up.

People in their 20s tend to jump into small, fledgeling companies, and that’s one of the best things you can do. A junior developer at Fidelity or Akamai is going to work on one thing for long periods of time, while at a start-up you’ll get a chance to jump all over the place, learning many different aspects of the field. But don’t fall into the trap of trading long hours and happiness for the gold ring of equity. You are never going to be in better shape, less constrained by responsibilities, or have more energy than you will right now. Burning 80-hour weeks grinding code is a terrible waste of that gift. Most companies crash and burn, and that equity they gave you will be just toilet paper. It won’t pay for the time you sacrificed eating take-out pizza in front of a glowing tube rather than enjoying the best years of your life.

If you’re passionate, you’ll do the job you’re required to do, and more, but don’t let your employer abuse your enthusiasm. One of my tenets of life has always been that “a lack of planning on your part does not constitute an emergency on my part.” There will be times in your life when you have to step in and fix genuine, unforeseen emergencies, and burn the midnight oil. But if you’re being asked to do it regularly, just because your company didn’t allocate enough resources to see the job through, you’re being played for a patsy.

Consider the benefits of loyalty to your employer. More than just about any other industry, software suffers from a nomadic workforce, where spending five years at a single company is rare. Remember that in a good work environment, you make friends as well as money, and as much as you may say you will, you never keep in touch with them when you move on. But don’t be afraid to jump ship if you are truly unhappy where you are, either.
Read more…

Comments: 2 |

Building Modern Web Apps, Build 2013, TechEd North America, and More

Tech events you don't want to miss

Each Monday, we round up upcoming event highlights from the programming and technology spaces. Have an event to share? Send us a note.

Modern Web Applications Utilizing HTML5 APIs webcast: Ido Green covers techniques and tools for building great “modern” web apps, including tips on Chrome DevTools, HTML5 power tools, and modern web app design techniques. Register for this free webcast.
Date: 10 a.m. PT, May 30 Location: Online webcast

TechEd North America: This is Microsoft’s main conference for IT professionals and enterprise developers. Get hands-on experience with more than 200 self-paced labs. If you need to convince your boss to let you go, there’s even a guide to help. For more information and to register, visit the TechEd website.
Date: June 3–6 Location: New Orleans, LA

Read more…

Comment: 1 |

In-Memory Databases, Burning Silos, Reintroducing Dart, and Google Glass Gatherings

Weekly Highlights and Insights: May 19-25

In-memory Databases: A discussion of near real-time manipulation of massive datasets

Burning the Silos: Minimize boundaries to reduce product cycle times.

Dart Is Not the Language You Think It Is: Seth Ladd’s enthusiastic reintroduction of Dart prompts a voluminous discussion on Slashdot.

Is that the Google Glass?: The anthropology of an always-on society

Tracing the Disappeared: An interactive visualization of CIA rendition flights

Comment |

How Web Pages Can Extend (or Drain) Mobile Device Battery Life

Dr. Angela Nicoara on mobile browser energy consumption and ways developers can minimize energy use through design.

According to recent Global Mobile Data Traffic Forecasts (PDF), the number of mobile-connected devices will surpass the world’s population this year, and by 2015, there will be 788 million mobile-only Internet users. A recent paper, “Who Killed My Battery: Analyzing Mobile Browser Energy Consumption (PDF),” pulled together by the Deutsche Telekom Innovation Center in Silicon Valley and Stanford University researchers and published in the ACM 21st International World Wide Web Conference (WWW 2012) proceedings (PDF), takes a look at the growing popularity of mobile web browsing and the effects on energy consumption.

I reached out to Dr. Angela Nicoara, senior research scientist at the Deutsche Telekom Innovation Center in Silicon Valley who worked on the project, to find out why mobile browser energy consumption is a growing concern and what developers need to know going forward. Our interview follows. Dr. Nicoara will present the researchers’ findings in the “Who Killed My Battery: Analyzing Mobile Browser Energy Consumption” session at the Fluent 2013 conference next week in San Francisco, CA.

Why is browser energy consumption becoming more of an issue with the growth of smartphones and mobile browsing?

Dr. Angela Nicoara

Dr. Angela Nicoara

Dr. Angela Nicoara: Despite the explosive growth of smartphones and growing popularity of mobile web browsing, their utility has been and will remain severely limited by the battery life. Smartphones’ energy constraints are here to stay, and as such, optimizing the energy consumption of the phone browser while surfing the Web is of critical importance today and will remain so in the foreseeable future.

Read more…

Comment |

Dart Is Not the Language You Think It Is

A terse language without ceremony

When Dart was originally launched, many developers mistook it for some sort of Java clone. In truth, Dart is inspired by a range of languages such as Smalltalk, Strongtalk, Erlang, C#, and JavaScript. Get past the semicolons and curly braces, and you’ll see a terse language without ceremony. Dart has evolved into its own, and here are some of my favorite language features.

Dart is a source code VM

The Dart VM reads and executes source code, which means there is no compile step between edit and run. As with other popular scripting languages, it’s very quick to iterate with Dart. The Dart VM runs on the command line and servers, and can be embedded into browsers. Just point the VM at Dart source code and you’re up and running!

Dart is optionally typed

Dart understands that sometimes you just don’t feel like appeasing a ceremonial type checker. Dart’s inclusion of an optional type system means you can use type annotations when you want, or use dynamic when that’s easier.

For example, you can explore a new idea without having to first think about type hierarchies. Just experiment and use var for your types. Once the idea is tested and you’re comfortable with the design, you can add type annotations.

Here is a comparison between code that uses type annotations, and code that uses var for dynamic. Both of these code snippets have the same runtime semantics:

With type annotations:

  void advance(double dt) {
    double dx, dy, dz, distance, mag;
    int size = bodies.length;
    for (int i = 0; i < size; i++) {
        Body bodyi = bodies[i];
        // ...

Or, without type annotations:

  advance(dt) {
    var dx, dy, dz, distance, mag;
    var size = bodies.length;
    for (var i = 0; i < size; i++) {
        var bodyi = bodies[i];
        // …

Type annotations are great for the “surface area” of the code (such as method and function signatures), and the tools are getting good enough for you to consider using var inside methods and functions.
Read more…

Comments: 45 |

JavaScript Flexibility: Fun, But Use with Care

JavaScript is dynamically typed

When you begin programming in JavaScript, you’ll need to use variables. A variable is just a bit of storage to hold a value. Just about every line of code you write will use a variable of one kind or another, so it’s a good idea to get familiar with the kinds of things you can put in variables, and how you can use them. Now, if you’re coming from another programming language, like Java, you might be surprised to see how loose JavaScript is about variables and their type. JavaScript doesn’t care if your variable starts out with a string value, and ends up being a number: JavaScript’s dynamically typed.

In this installment of Head First JavaScript Programming Teasers, you’ll learn about the basics of variables, how JavaScript is dynamically typed, and why it’s a good idea to stick with one type for your variables.

Comment |

Upward Mobility: Special Effects Wizardry

Dress up your UIViews with a few simple tricks

Most developers aren’t great UI designers (although, as with everything, there are exceptions). But there are a few quick tricks that can dress up an app, even if you don’t eat and breathe Photoshop. Let’s look at a simple iPad single-view app with two views, each of which contains a label and a text box.

iOS Simulator Screen shot May 20, 2013 7.05.42 AM

This is about as Plain Jane as you can get in an application; the only concession to visual appeal that has been made is to use a grey background with white UIViews bounding the labels and text boxes. One easy tweak we can use is to make the UIView corners rounded instead of square, which will lend a bit of flare to the design.

This is actually harder than it should be. To set rounded corners, you need to dig down into the CALayer underneath the view:

#import <QuartzCore/QuartzCore.h>
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.topView.layer.cornerRadius = 5;
    self.topView.layer.borderWidth = 1;
    self.topView.layer.masksToBounds = YES;
    self.bottomView.layer.cornerRadius = 5;
    self.bottomView.layer.borderWidth = 1;
    self.bottomView.layer.masksToBounds = YES;
}
@end

You need to set masksToBounds, because otherwise the corners will not be transparent, and the background color of the view will block whatever is beneath it in the parent view. The resulting view is subtly more classy. You can get more rounding by adjusting the cornerRadius value.

Screen Shot 2013-05-20 at 7.17.42 AM

 

So far, so good. But that solid grey background is kind of blah, so we should dress it up a bit. An easy way to make a background pop is to use a gradient fill, a technique that the aforementioned Photoshop jockeys know and love.
Read more…

Comment |