Pages

Showing posts with label 1. Show all posts
Showing posts with label 1. Show all posts

Monday, March 9, 2015

How It’s Made Election Info App Part 1

In an earlier blog post, we announced the Election Info sample app. We briefly talked about how we were able to use Apps Script to easily create a comprehensive sample application that provided timely voting information. This post shows just how easy it is to use Apps Script to get information from an external API and integrate with various Google services to create a rich web application and provide a meaningful user experience.

UrlFetch

First, we use UrlFetchApp to get JSON from the Google Civic Information API and use Utilities.jsonParse to convert it to a useful javascript object.

var url =
https://www.googleapis.com/civicinfo/us_v1/voterinfo/2000/lookup;
var address = { "address" : "1263 Pacific Ave. Kansas City KS" };

var options =
{
method : "post",
contentType : "application/json",
payload: Utilities.jsonStringify(address)
};
var responseText = UrlFetchApp.fetch(url, options).getContentText();
var response = Utilities.jsonParse(responseText);

After getting the response object, we can simply drill into it to access various data provided by the API.

Calendar Service

One of the things the response object provides us with is the election date. Using Apps Scripts Calendar service, it is really easy to create an event on voting day in the users calendar with the polling address. First, we create a Date object from the date string. We then create an all-day event on the default calendar on this date, passing along the polling address we get from the response object.

// create a Date object from the response date string 
// ("2012-11-6" --> Date object)
var [year, month, day] = response.election.electionDay.split(-);
// javascript months are zero-indexed
var electionDate = new Date(year, month-1, day);
// get the first polling locations address
var pollAddress = response.pollingLocations[0].address;

var cal = CalendarApp.getDefaultCalendar();
cal.createAllDayEvent("Go Vote!", electionDate, {location:pollAddress});

Maps Service

Using the Maps service, we can generate static maps with the users home or polling address as shown in the following code snippet. We display these maps on the web app page, then embed them in the reminder email and bring-along document as we will show in the following sections.

var userAddress = response.normalizedInput;
var normalizedAddress = userAddress.line1 + +
userAddress.city + , +
userAddress.state + +
userAddress.zip;
// normalizedAddress looks like "501 Kildaire Rd Chapel Hill, NC 27516"
var staticMapUrl = Maps.newStaticMap().setSize(600, 300)
.addMarker(normalizedAddress)
.getMapUrl();

Gmail Service

We also provide a simple method for users to email themselves all of this information. Using the Gmail service, we can send an HTML email that embeds the voting information and the static maps we generated above. The Apps Script documentation contains great tutorials such as the Maps tutorial we used to generate the directions below.

var email = Session.getActiveUser().getEmail();
var body = Election Date: + electionDate + <br/>
+ Your polling address: + pollAddress + <br/>
+ Polling Hours: + pollingHours + <br/>
+ <img src=" + directions.mapUrl + "/> <br/>
+ Directions: + dirList;
MailApp.sendEmail(email, Upcoming Election Voting Information,
Voting Info, {htmlBody: body});

Document Service

Using the Document service, we were able to easily generate a bring-along document with polling address, hours, and directions. The follow code excerpt shows how easy it is to add different elements like headers, tables, and paragraphs to a document. Apps Script also provides an extensive list of methods to programmatically control the look and presentation of the various elements.

var title = "Voting Information";
var doc = DocumentApp.create(title + " for " + homeAddress);

var reportTitle = doc.appendParagraph(title);
reportTitle.setFontFamily(DocumentApp.FontFamily.ARIAL)
.setFontSize(22).setForegroundColor(#4A86E8)
.setBold(true)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
var header = doc.addHeader();
header.appendParagraph(Generated by the Election Info application +
built on Google Apps Script)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER)
.setAttributes({ITALIC : true});

var tableStyle = {};
tableStyle[DocumentApp.Attribute.PADDING_BOTTOM] = 0;
tableStyle[DocumentApp.Attribute.PADDING_TOP] = 0;
tableStyle[DocumentApp.Attribute.PADDING_LEFT] = 0;
tableStyle[DocumentApp.Attribute.PADDING_RIGHT] = 0;
var addressTable = doc.appendTable([
[Your address: + homeAddress],
[Your Polling Location: + pollAddress],
[]
]).setAttributes(tableStyle);

// add appropriately sized poll location image
addressTable.getCell(1,0).appendImage(pollImg.getBlob())
.setHeight(300).setWidth(600);

// populate last row of the table with polling hours
addressTable.getCell(2,0).clear().appendParagraph("Polling Hours: ");
addressTable.getCell(2,0).appendParagraph(
UserProperties.getProperty(Keys.POLLING_HOURS));

Here is an image which shows the generated bring-along document embedded with static map images from the Maps service.

Apps Script allowed us to easily take information from an external API and tie it into various Google services to provide a great user experience. Stay tuned for an upcoming blog post showing how we created the front end!


Kalyan Reddy profile | Stack Overflow

Kalyan is a Developer Programs Engineer on the Google Apps Script team based in NYC. He is committed to increasing developer productivity by helping them fully utilize the power of Apps Script. In his free time, he enjoys participating in the Maker community and hacking together robots.

Read more »

Sunday, March 1, 2015

Teaching Habits That Inspire You Out of Learning Part 1

  • Link to ZaidLearns Del.icio.us Teaching Links

“The mediocre teacher tells. The good teacher explains. The superior teacher demonstrates. The great teacher inspires.” - William Arthur Ward

Can anyone become a great educator (teacher or lecturer)? Or is it gift that we are born with (Nature)? Or can we become a great educator through learning, practice, feedback, reflection, etc. (Nurture)? Or perhaps it is a combination of Nature and Nurture? Or perhaps it is neither? What are the characteristics of a great educator anyway?


WHAT GOOD TEACHERS SAY ABOUT TEACHING?
"At the University of California at Berkeley, the Distinguished Teaching Award was instituted in 1959 to recognize and reward excellence in teaching. Since the inception of the award, over 150 faculty in forty-eight departments have been honored...although these essays (by the award winners) were prepared independently over a number of years, there are striking similarities about what good teachers say about teaching. On at least ten propositions, the contributors are in near or total agreement (Source):
  1. The teachers main task is to guide students through the learning process, not to dispense information.
  2. The goal of teaching is to help students read, speak, write, and think critically—and to expect students to do these things.
  3. Learning is a "messy" process, and the search for truth and knowledge is open-ended.
  4. Good teachers love their subject matter.
  5. Good research and good teaching go hand in hand. Students engagement with the subject is enhanced by knowing about the teachers own research, and the interaction with students often provides new insights into the research.
  6. The best teachers genuinely respect students and their intellectual capabilities.
  7. Good teachers are rarely satisfied with their teaching. They constantly evaluate and modify what they do.
  8. Good teachers usually had good teachers, and they see themselves as passing on their own teachers gifts to a new generation of students.
  9. Good teachers treasure the small moments of discovery in the classroom and the more enduring effect they have on students lives.
  10. Good teachers do not see teaching as separate from other activities; rather, they see their lives as remarkably integrated."
The interesting thing today, is that we increasingly have access (if we have Internet!) to all sorts of content about the art of excellent teaching (A short list). In addition, we can also study and reflect amazing lecturers through video lectures and podcasts from many of the most respected Universities around the world, including MIT, Harvard, Yale, Oxford and Cambridge (YouTube Channels, Podcasts and OpenCourseWare).
So, why cant we inspire all our students to learn (if you can, please share your secret!)? That is a tough question beyond my intellect, knowledge and experience (I suppose because it needs two to tango)! However, lets play a bit with this question, and instead ask, "what were the least inspiring teachers we experienced during our student days?" Or more specifically, "What were the teaching habits that inspired us out of learning?"


5-PART SERIES?In this 5-part series (which might evolve into a 10-part series!), I will reflect specific teaching habits practiced by some educators that I experienced personally during my 20 years career as a student (I suppose when I do my PhD I can add another 3-4 years). I am not interested in witch hunting any particular educator (I am really bad with names anyway, so that is not a problem!). Instead, I am trying to reflect back and learn from their teaching habits (and perhaps avoid them!) that made me wonder: Are you kidding me? Is this guy for real? This guy needs a life! What is wrong with him? Cant he see that we are sleeping! Dont teachers undergo training on how to teach and facilitate learning? Perhaps he doesnt care!
Since I have had the privilege to experience educators from every major continent of the world during my 20-year career as a student, I suppose I will have some very interesting teaching habits to share with all of you. Whether they are bad teaching habits or not, I will leave that for you to decide. But one thing is for sure, these teaching habits certainly inspired me out of learning.
Finally, before we begin this unlearning journey, I have to admit I have never been an easy student to deal with. During my primary and secondary school I was rude, noisy, and spent a lot of time in detention. I literally slept through high-school, and just managed to scrape through. Once, one lecturer threatened to kick me out of class if I didnt stop sleeping, and even placed me in the front row to ensure that I didnt sleep. It didnt help much! When you are tired, and have to sit through a boring lecture, what do you expect! I suppose if I had taken more vitamin supplements, given up on football, stopped having fun, and slept earlier, things would have been different. I suppose it is a learning process!
Then I moved to Malaysia, and the power of faith (Islam) brought the passion back to learn in me. During my undergraduate and graduate days, I forced myself to sit in the front row until it became a habit I am proud of. Not only did I sit in front, I also become the ultimate annoying student that always asked questions. I became the kind of smart-aleck I used to despise in my younger days. In a nutshell, that is my story as a student. Now, lets move on to the real point of this 5-part series.


WHITEBOARD AND I ARE ONE!
During my undergraduate studies, I had a very interesting statistics lecturer, which I will name Dr. Woody (woodpecker) for the name protection sake. Dr. Woody was a multimedia encyclopedia of statistics, and he certainly did not need to refer to any book or notes during his lectures. He had perfected every lecture he conducted. In addition, he was a caring guy and always smiled. So, what is the problem! Yeah! Hmm, got a point there!
Interestingly, I had two different statistics (cant remember the names!) subjects with Dr. Woody that semester, and we only had a 10-minute break in-between the two 90-minute sessions twice a week (6 hours a week with Dr. Woody).
Dr. Woody was always punctual and so was I. I remember, he would always be stressed at the beginning of each class and would be eager to start as fast as possible, so that we could complete the syllabus on time. As soon as he began teaching, he would face the whiteboard with his markers, and begin the magic statistics writing adventure. And you know what, he would just go on, and on, and on, and on, like a dog hunting a fox. His urgency to do his thing (teach!), gave him no time to turn back and assist the helpless students in shock! We managed to complete 50% of the syllabus within the first 3 weeks of a 14-week semester. Of course it was impressive to see Dr. Woody practically write the book on the whiteboard, doing it at a speed that even Ferrari would not be able to match.
My fingers (and brain) used to be really exhausted after two consecutive 90-minute sessions (twice week) of nonstop writing (15-25 pages of notes each time!), trying to capture everything that Dr. Woody wrote on the whiteboard. Thank GOD many lecturers today use PowerPoint, or provide some form of course notes. However, we have to keep in mind that taking notes itself, is a skill that all students should master. Because in most working environments, there probably wont be any books or notes to rescue us, and solve all our problems. 


REFLECTIONIt was only after I discovered notes taken from his previous students that I realized how amazing Dr. Woodys memory was. It was as if he had imprinted the notes and formulas in his brain, and simply repeated it again and again every semester. Even a photocopy machine would be proud of such perfection. Although, we got to experience him do his thing (process flow!), it was kind of overwhelming, and I believe most of us had problems dealing with the information overload. I suppose if we could replay the lecture in slow motion (many times!), it would be more useful.
Interestingly, when I revised the notes I had taken from Dr. Woodys lectures, I couldnt even remember that I had written them. Did I really write that! I suppose I had no time to think while taking the notes.
Overall, Dr. Woody was knowledgeable, skillful, caring, experienced, and an expert in his subject area. However, I am not sure I learned much about statistics from him. Actually, I didnt! Though, since I had the passion to do well, I managed to do quite well anyway.
But, what is important to keep in mind here, is that being an authority in a knowledge domain, does not mean that we are fit to educate and facilitate learning. Even worse, some educators have an amazing ability to make you sick of a subject (They might argue that it is self-inflicted!). Is that a natural gift, too?
Although, it is important to learn new ways to improve our teaching, it is also important to reflect our own existing teaching methods, and perhaps unlearn those that really inspire people out of learning.
Until Part II, lets explore our own teaching, and try to point out to ourselves (at least!) a few habits that might turn students off learning.
"That student is an idiot! I have told him a 100 times and he still doesnt get it!" :)


5-PART SERIES
  • Part 1 - Whiteboard And I Are One! 
  • Part 2 - I Have Bragging Rights, Because I Am … 
  • Part 3 - Is PowerPoint Evil? 
  • Part 4 - No Stupid Questions! I am Serious! 
  • Part 5 - Show Up to Throw Up! 21st Century Thinking?
Read more »

Saturday, February 28, 2015

My First Keynote Part 1

  • SlideShare Version
  • SlideBoom Version
  • PDF Version (77 MB)
  • IMETC Event


FIRST KEYNOTE

On this coming Wednesday (5th November), I will hopefully be giving my first keynote presentation at the 2nd International Malaysian Educational Technology Convention (IMETC). If things go as planned, I will be the first speaker at the event, which should generate some big butterflies in my stomach. But strangely enough, I am actually looking forward to it (at least for now!). And currently my biggest worry is to be able to discuss (in human understandable way!) my 100+ slides within the one hour given. Now, that is a challenge! Hopefully, I will be able to say the things I want to say.

"Rehearse and use a script, please!" Good idea, but I want it to have a natural flow (A learning conversation with the audience and myself), so no script, except for the slides (Though, if I was a President I would use one!). I hope my ideas and reflections will be free flowing guided by the spicy slides. It will be an interesting experiment, which will be revealed in Part 2. Also, Part 2 (next post) will discuss and reflect all the things I would have learned during this 3-day learning adventure. No, I am not yet ready for any live UStream show!


PRESENTATION SLIDES

In the keynote presentation, I will first discuss a bit about how my first ebook entitled 69 Learning Adventures in 6 Galaxies came to life. Then, I will explore some learning or thinking skills we need to nurture in students and ourselves to be successful in todays fast evolving innovation world. I will also look at some of the educational challenges we might face, and explore a case study on how I revamped a critical thinking course. Finally, I will look at some possibilities and conclude the learning overload session. In short, we are all probably going to get dizzy (learning overload!) one way or the other. Anyway, here are the slides to enjoy before the actual event:

69 Learning Adventures in 6 Galaxies

Interestingly, the slides have already been featured on SlideShare homepage (within 3 hours upon upload). So, at least the slides seems to be a bit interesting. Lets hope the actual keynote presentation also turns out to be interesting, engaging and useful to those attending the event.

I suppose after all my past workshops and 20-minute presentations (taken a 2-year break from that!), I kind of look forward to this great opportunity to talk for one hour (or less) to a bunch of people about the things I have learned over the last few years. And for that, I am truly grateful to God (Allah) and would like to also thank the organizers for giving me this opportunity. Thank you so much!

Until part 2, have fun trying to make sense of my slides. If they dont make sense, perhaps you could invite me to give a talk. Though, I would prefer if I was given 2 hours. Meaning, we will have approximately one hour to discuss, reflect and learn together. Now, that is where the real learning will take place :)
Read more »

10 Secrets to Great Teaching Part 1

  • TeacherTube version
  • YouTube
  • Google Video

PART 1
In part 1, I explore 4 (of 10) secrets to great teaching, or ingredients to become a great teacher. What are the ingredients of a great teacher? Well, when I complete the 2-part series you will at least know my standpoint on this issue. My findings is basically based on what I have observed, read, experienced and learned over the last few years in Higher Education.

Yes, you are certainly free to agree or disagree with all my ideas and thoughts about great teaching. What really matters, is not being right or wrong, but taking this wonderful opportunity to be part of a messy global conversation (in audio format) about this issue.

Here, enjoy part 1 (not sure about that!), and hopefully part 2 will be out sometime next week:


ZAIDLEARN EXPLORES AUDIO & VIDEO
This is probably the first time most of you hear me speak. I have to admit that I speak much faster normally (I tried hard to slow down, and probably sounded a bit too slow this time around.). Also, I did not use any script, as I wanted it to be as natural as possible.

I used PowerPoint to create the slides, and interestingly (exploring!) used Adobe Presenter to record the audio (Recommendation: For audio recording, use Audacity, which is easy-to-use and has more features). Finally, I used Windows Movie Maker (first time using!) to integrate the PNG converted PowerPoint slides, and the audio (MP3) files from the published Adobe Presenter presentation. Although, Windows Movie Maker is quite limited in terms of features, I actually enjoyed using it.

To explore uploading possibilities, I uploaded my 10-minute presentation to YouTube, TeacherTube and Google Video. The Google Video output is not good, but the YouTube and TeacherTube outputs are alright. I suppose I will explore slidecasting on SlideShare later, after I have completed part 2.

SELF-EVALUATION
My voice is a disaster and the PowerPoint slides need a face lift! Yes, perhaps I should include more music (to spice it up!), pictures, and flower it with a bit more animations. A video showing me babbling would be interesting, too (not really!).

Though, I really enjoyed exploring my voice, and hopefully I will create many more videos (learning nuggets of 10 minutes or less) sharing my ideas, thoughts and reflections about learning in the near future. Hopefully, someone out there will be listening and joining the conversation.

I suppose it is about time that ZaidLearn speaks out, besides rambling this and that with written words only.

I AM STILL LEARNING, and hopefully I will evolve. In the meantime, please be patient as I learn how to talk (on the Tube) :)

Read more »

Saturday, February 14, 2015

Need for Speed Underground 1 for PC full version with system requirements


Review:
Need for Speed Underground borrows, instead of simulating, from the increasingly popular custom kit and import car scene. The days when Dodge Neons, VW Golfs, Subaru Imprezas and Mazda Miatas were just reminders you couldnt have a flashy sports car are gone; in the ever-growing circle of elite street racers, dedicated auto fanatics are turning the mid-range class of almost-sports-cars into decked out, eye-catching street rockets. The underground scene of backstreet, nighttime racers has evolved into a whole new industry. Companies like AEM, Enkei, Jackson Racing, HKS, and StreetGlow provide lines of custom upgrades for otherwise everyday cars -- like the Impreza -- so you can deck them out and turn them into your personalized street machine.


Black Box and EA have gone to great measures to capture this gritty, sometimes seedy underworld, partnering with the biggest product lines and major car manufacturers. It seems its goal was to create a racer that provided more vehicle customization than anything ever seen before, and to this extent it succeeded brilliantly. The flexible car customization mode offers up 20 different vehicles, not a huge number, but with all the different options the variety of personalized cars you can create is in the billions, according to EA. These "Customize Your Ride" options take center stage of the gameplay. Undergrounds single-player mode is intimately tied into unlocking new parts for your car -- both of the performance increasing and aesthetic variety.

The total gameplay experience is tuned into the 111-objective "Underground" mode. Like a story, it unfolds as your challengers message you via your in-car video display. There are a few FMV sequences now and then, but mostly it is just audio clips and animated heads that deliver your objectives. It works perfectly, however, and is presented seamlessly. To diversify gameplay from just being regular racing as weve seen it before, Black Box crafted a number of different race types -- essentially you have Race, Drift, and Drag. Race is actually broken up into a number of styles, including point-to-point (one long stretch of a track), circuit (multi-lap), and knockout (cars in last place are booted each lap; last car across the line wins). So, theres a respectable variety to mix up Undergrounds story mode. Read more

System requirements:
MINIMUM PC REQUIREMENTS
Windows 98/ME/2000/XP
Pentium III or AMD Athlon 700MHz Processor
128MB RAM (256MB for 2000/XP)
8X CD-ROM/DVD-ROM Drive
2.0GB Hard Disk Space
32MB Direct3D compatible Video Card
DirectX 9.0
Keyboard
Mouse
MULTIPLAYER SYSTEM REQUIREMENTS
Broadband Internet Connection
256MB RAM

Screen Shots: Click on the image to view large
pic namepic namepic name

How to Download
File Size: 163 MB
Need for Speed Under Ground 1 for PC: Download
I hope you like it......!
Read more »

Friday, February 13, 2015

LOARIS TROJAN REMOVER 1 2 5 0 FULL VERSION WITH CRACK


Info:
Loaris Trojan Remover – a program with which you can completely clean your computer from Adware, Spyware! Are you bombarded with popup ads, seeing new toolbars in your browser, your home page changing to unwanted destinations or are you bombarded with irritating spam? Perhaps strange software loads on startup or your favorites have new entries that you do not want. If so .. Your PC is likely infected with adware, spyware, spybot, Trojans or other Internet parasites. These programs have the ability to track your habits (by tracking requests, ARP yes you visit the Internet), and even steal such personal information as bank account numbers and passwords. Spyware can install more parasites on your computer without your consent. Everything you do and everything you type is being recorded right now! Companies know what your interests are!

Hackers can access your PC and do whatever they want. They can even steal your identity! Solution: Download the latest version Loaris Trojan Remover right now. You will be able to completely clean your computer of all these invasive threats! Your computer will be clean and will run a lot faster – Your Privacy will be Protected! Appendix Loaris Trojan Remover aids in the removal of malicious software: Trojans, Worms, Adware, Spyware – when standard antivirus software or are unable to detect them or fails to effectively eliminate them. Standard antivirus programs are good at detecting this Malware, but not always good at their disposal. Trojan Remover is designed specifically to remove these programs without having to manually delete them. The program also removes the additional system upgrades that have been introduced malicious software. Trojan Remover scans all files downloaded during the launch system, the presence of Adware, Spyware, Trojans, Internet worms, etc. Two types are available. Standard antivirus scans the system without the need for further choosing. Utility will choose any of the folders to scan.

Additional Tools:
• Reset Internet Explorer Home/Start/Search Page Settings
Some Malware programs make changes to the Internet Explorer Home, Start and Search Page settings in order to re-direct the web browser to different websites. This Utility will reset the Home/Start/Search pages to standard Defaults. You can then manually reset your Home Page to your website of choice (or leave it “blank”, the default).
• Reset HOSTS file
The Windows HOSTS file is a text file which stores website addresses. The file can be used to speed up access to websites you visit often – by equating the website name (e.g. microsoft.com) with its DNS address, the web browser can find the website more quickly as it does not have to query a DNS Name Server. Some Malware programs add entries to this file, to either deny access to websites (usually security-related or antivirus company websites), or to re-direct access to websites of their choosing.
• Reset Windows Update Policies
Some Malware programs attempt to prevent Windows Update from running, and inhibit access to resetting Windows Update by blanking out the Windows Update options on the Update configuration screen. This Utility will check the current Windows Update settings and correct them where necessary.

Screen Shots: Click on the image to view large screen
pic namepic namepic name

Download

click to begin

27.8 MB

I hope you like it......!
Read more »

Wednesday, February 11, 2015

C Program to Print Numbers From 1 to n Without Using Loops Recursion or Goto Statement

You may have made program to print numbers from 1 to n using loops, recursion or goto statement. But have you ever thought about doing this without help of loops, recursion or goto? It can be done without using such things as explained in below program.

Also Read: C program to find factorial of any number using recursion
Also Read: C++ Templates: Program to Swap Two Numbers Using Function Template

#include<iostream>

using namespace std;

class Num
{
    public:
    static int i;
    Num()
    {
        cout<<i++<<" ";
    }
};

int Num::i=1;

int main()
{
    int n;
    cout<<"Enter value on n:";
    cin>>n;
    Num obj[n];
    return 0;
}

In this program we are using the concept of static data member and array of objects. Class Numcontains a static variable i whose value will remain till the program terminates. We are creating an array of objects of class Num. In this program we are creating n objects, value of n depends on input we give. The default constructor is called for all objects one by one. In the constructor the value of i is printed and is incremented by one in each call. In this way numbers from 1 to n are printed.

C++ Program to Print Numbers From 1 to n Without Using Loops, Recursion or Goto Statement

If you have any doubts or any suggestion regarding above program then you can ask it by commenting below.

Source: http://www.geeksforgeeks.org/output-of-c-program-set-18-3/
Read more »

C program to print fibonacci series i e 0 1 1 2 3 5 8


#include<stdio.h>
#include<conio.h>

void main()
{
int first=0,second=1,third,i,n;
clrscr();  //to clear the screen

printf("Enter how many elements?");
scanf("%d",&n);
printf("
%d %d",first,second);


for(i=2;i<n;++i)
{
third=first+second;
printf(" %d",third);
first=second;
second=third;
}
getch();  //to stop the screen
}
Read more »

Thursday, February 5, 2015

Seven Languages in Seven Weeks Scala Day 1

Its time for a new chapter in the Seven Languages in Seven Weeks series: today, I take a crack at Scala.

Scala, Day 1: Thoughts

After using Java for years, I was curious to try out Scala, which has often been described as the next step in the evolution of Java. Scalas feature list is impressive: object oriented, functional, type inferencing, traits/mixins, currying, pattern matching, concise syntax, interoperability with Java code, an active community, and so on. My previous experiences with Scala had been very shallow/short, so I was excited to take a slightly deeper dive.

The first chapter introduced the imperative and object-oriented features of Scala and walked through the basic syntax. On the surface, the language looks like Java and uses many of the same keywords, so I was able to jump right in. However, I was quickly slowed down by some unexpected differences, including types specified after the variable name instead of before, "static" methods and fields separated into "companion classes" (confusingly named "objects"), and methods definitions sometimes including or omitting an equals sign and or parentheses depending on whether they return values or take parameters as inputs.

I slowed down even more once I started looking at the functional programming concepts and, worst of all,  trying to make sense of the API docs. Although they look thorough, the docs are astonishingly bad when you actually try to use them. For example, here is all the documentation provided for the "reduce" method of Scalas List:


If youre new to Scalas syntax, functional programming, or just a hacker trying to get something done, this sort of documentation is almost useless. Plain, human English or an example would be an order of magnitude more useful. The reduce concept isnt actually that hard to understand, but parsing the dense syntax of the method signature and phrases like "associative binary operator" makes it seem like a PhD is necessary to use this language. Compare this to the reduce documentation for Ruby and underscore.js to see a world of a difference.

The type hierarchy also proved tough to navigate. For example, how do I find the closest common ancestor between List and MutableList? I thought it might be LinearSeq, but there seem to be separate mutable and immutable versions of it. Other classes/traits further up the hierarchy overlap, but are missing common methods I need, such as "collect" or "foldLeft". Overall, this basic search was much harder than, for example, finding the common ancestor between Java libraries like ArrayList and Vector: a glance at the top of the API doc and youre done.

I also ran into difficulties with type inferencing. It definitely saved me some typing and looked beautiful for simple cases and closure parameters. However, type inference couldnt handle many cases that seemed obvious. This was compounded by the sub-par IDE support, at least from IntelliJ 11, which took a while to get working in the first place. I routinely found code that IntelliJ accepted wouldnt actually compile. Oh, and the compiler is slow. Ridiculously slow, given the tiny snippets of code I was testing.

Having said that, Im still a newbie to the language, and shouldnt complain too much. Im sure Ill get used to the code, API, and Scala idioms. Still, there is value in being "hacker friendly": one of the reasons Ruby, PHP, and JavaScript have such huge user bases is because you can get started with them in minutes. And theres also something to say about complexity: Scala has a lot of features, syntax, and complicated concepts. I hope that these make the language more powerful and expressive rather than bloated and incomprehensible.

Scala, Day 1: Problems

Build a two player Tic Tac Toe Game

The code:


Sample output:


I tried to keep the code fairly generic, so it should work for any NxN tic tac toe board. I also used this as an opportunity to play with some functional programming, so I intentionally stuffed everything into a List (albeit a mutable one), avoided for loops, too many objects, and so on. To be honest, Im not thrilled with the result.

I was able to use lots of one-liners, but many are hard to read. I got familiar with the fold, map, and filter methods, but in some cases, a for-loop wouldve been much cleaner (and faster). Overall, I just get the feeling that the code doesnt communicate its intent very well. Id love some feedback from how a more seasoned Scala user wouldve tackled this problem. Would pattern matching be useful? Recursive calls on the head/tail of the List? Or is the imperative style with loops and a 2D array the best way to go?

On to day 2

Continue on to Scala, Day 2.
Read more »

Tuesday, February 3, 2015

HTML5 Simplequiz 1

A few years ago, Dan Cederholm published a series of articles called Simplequiz in which he posed some options for marking up a specified piece of content and invited readers to choose the one they felt was the best way to mark that up. The value was in the comments in which people said why they made that choice and debated the options (which means it is THE LAW that you read the preceeding comments before adding your own).
With Dan’s blessing, we’re beginning an occasional series of HTML5 Simplequizzes. And here’s the first.
Consider a products page on a website. It might be a page showing widgets, HTML5 books or Remy’s favourite nose hair removers. What’s the best way to mark up the products?
Note: please DON’T USE ANGLE BRACKETS in your comments. Escape them with &lt; and &gt; or just use [foo] – we’ll know what you mean.

A:

<div>
<h2>Groom Mate Platinum Xl Nose & Ear Hair Trimmer by Groom Mate</h2>
</div>
<div>
<h2>Philips NT9110 Nose Hair Trimmer by Philips<h2>
...
</div>

B:

<article>
<h2>Groom Mate Platinum Xl Nose & Ear Hair Trimmer by Groom Mate</h2>
...
</article>
<article>
<h2>Philips NT9110 Nose Hair Trimmer by Philips<h2>
...
</article>

C:

<section>
<h2>Groom Mate Platinum Xl Nose & Ear Hair Trimmer by Groom Mate</h2>
...
</section>
<section>
<h2>Philips NT9110 Nose Hair Trimmer by Philips<h2>
...
</section>

D:

<nav>
<div>
<h2>Groom Mate Platinum Xl Nose & Ear Hair Trimmer by Groom Mate</h2>
...
</div>
<div>
<h2>Philips NT9110 Nose Hair Trimmer by Philips<h2>
...
</div>
...
</nav>
Your answers below, please, with your rationale.
Read more »