programming

Windows 8.1 Preview and Visual Studio 2013 Preview

At the build conference (June 26-28, 2013) Microsoft announced Windows 8.1 Preview and Visual Studio 2013 Preview. I installed them on my Virtual Machine. Just in case, to protect my system from some unexpected features 🙂

In case of Windows 8.1 there are no big changes. Only some small, useful improvements. I like ‘search all’, which enables you to search within apps, settings and files in the same time. However I am still using Search Everything, because it’s faster and more effective. It’s also cool to have the Start button, which brings you to the metro desktop, but again – no big deal (I was ok with WIN button). You can find list of improvements/changes here and here.

The new Visual Studio is more interesting. The One ASP.NET idea is applied. When you create new project, there are only one template: ‘ASP.NET Web Application’. Then in second step, you can choose which types of applications you want to include into it.

Visual Studio 2013 One ASP.NETVisual Studio 2013 One ASP.NET templates

There is MVC 5 (Preview) in it, along with various scaffolding options. You can e.g. scaffold just edit action.

Great feature for web developers: you can open page in multiple web browsers and then refresh them all from Visual Studio (e.g. after change in code).

The editors experience is improved. You can have code map in the scroll bar. HTML editor is rewritten from scratch. Short list of my favorite features:

  • new code snippets (in HTML document try: ‘div.myClass*4>lorem’ and click TAB)
  • intellisense in web.config
  • ALT + UP/DOWN – move code line up or down
  • ALT + 1/2 – extends text selection to level up or down
  • ALT+SHIFT+W – allows to surround selected text with new tag
  • ALT+V – voice commands (which shows shortcuts), yes we can speak to Visual Studio!
  • JavaScript frameworks intellisense (e.g. AngularJS)

But the greatest news is: WebEssentials2013 are now Open Source on github. Everyone can contribute. The policy is to add experimental features to WebEssentials and then move the hottest to Visual Studio (once they are tested). To see all, new, hot features watch Mads Kristensen’s talk at build 2013.

Another cool thing is possibility to ‘sign in’ in the Visual Studio. Once you sign in using your Microsoft account, you can synchronize settings across your devices. Now, it is enough to customize you Visual Studio only once.

There is much more new features. You can find them here and here.


The future of Mobile Apps

I think that in next 5 years Web Mobile apps will be more popular than classic Mobile apps we are using today.

Me, June 28, 2013

That is what happend in case of PCs. 10 years ago we were installing apps instead of just use them in the browser. Now we can edit Word documents, play games and even use IDE in Web Browser. I am not saying that it will be no classic Mobile apps at all, but e.g. apps like Calendar, gmail, Evernote, OneNote or games should be easilly accessible through Mobile Web Browser. The advantage of that would be lack of necessity to install bunch of apps.

What that means for developers? People who are currently working as Mobile Developers will need to learn Web Development. People who are currently working as Web Developers will need to learn Mobile Development. Additionally, future developers will not necessary need to know all different platforms (iOS, Android, WP), because they will be able to create apps in HTML5 and JavaScript (which should be well supported and compatible with Mobile Web Browsers in next 5 years).

This is my prediction. We’ll see what happens after 5 years.


Python jump start

In my current job (Research Assistant at SAnToS lab) I had to learn Python. I was very happy because of that. It gaves me an opportunity to get familiar with one of the most popular programming languages nowadays.

I was very lucky to find awesome Google’s Python Class by Nick Parlante. It is great! If you want to start programming with Python or just learn it for fun, start with this tutorial!

As a supplement to above course you can read some more detailed tutorial. I went through two: Learn Python The Hard Way and Tutorial from Python documentation. However if you already know some other programming language(s), your should learn during development. Python contains almost all common features of programming languages such as if/else, loops, exceptions, functions, classes etc. I said ‘almost’, because there is e.g. no switch instruction. However to check things like that there is very well written documentation. It contains a lot of examples. The main difference between other popular languages like (C, C# or Java) and Python is that there is no semicolons. We use colons and indentation instead.

if number > 0:
  print "This is natural number."
else:
  print "This is not natural number."

Python is dynamic, strongly typed programming language. It means type checking occurs during the run time, instead of compilation time. Programming in Python is a real pleasure. Sometimes you can explicitly put your mind into the code. That is because of high level of abstraction. E.g. file operations are so simple and intuitive. You do not need to remember any StreamReaders or BufferedReaders and bunch of functions for simple I/O operations. Below example reads content of file.

f = open('file.txt')
f.read()
f.close()

Cool feature is the possibility to call functions explicitly on string. Like that:

"jakub".upper()

There is a lot of implemented (widely used) functions in Python. As a comparison, let’s see how to reverse words in a sentence using C, Java and Python.

In C:

void reverse_words(char *sentence)
{
   char *start = sentence;
   char *end = sentence;

   while (*end != '\0') {
      ++end;
   }
   --end;

   reverse_chars(start, end);
   
   while (*start != '\0') {
      for (; *start != '\0' && *start == ' '; start++) ;
      for (end=start; *end != '\0' && *end != ' '; end++) ;
      --end;
      reverse_chars(start, end);
      start = ++end;
   }
}

void reverse_chars(char *left, char *right)
{
   char temp;

   while( left < right) {
      temp = *left;
      *left = *right;
      *right = temp;
      ++left;
      --right;
   }
}

In Java:

public string ReverseWords(string sentence)
{
  string[] words =  sentence.split(" ");
  string rev = "";
  for(int i = words.length - 1; i >= 0 ; i--)
  {
    rev += words[i] + " ";
  }
  return rev;
}

In Python:

def reverse_words(sentence):
  return " ".join(reversed(sentence.split(" ")))

That’s why Python is good for Rapid Development.

I am also using PyGTK (graphic library for Python) in my work. There is a great tutorial Python GTK on youtube! PyGTK requires very less code than e.g. C# to create some simple application. We do not to have tons of generated code when we start. We create application from scratch. Look at below Hello World example.

import pygtk
pygtk.require('2.0')
import gtk

class HelloWorld:
    def hello(self, widget, data=None):
        print "Hello World"

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(10)
        self.button = gtk.Button("Hello World")
        self.button.connect("clicked", self.hello, None)
        self.window.add(self.button)
        self.button.show()
        self.window.show()

    def main(self):
        gtk.main()

if __name__ == "__main__":
    hello = HelloWorld()
    hello.main()

The result is the window with button ‘Hello World’. When you click the button, then ‘Hello World’ will be printed on console. All of that with 22 lines of code (I do not count white lines).

Hello Python

If you don’t know python yet, I encourage you to try it. Programming in python requires a little bit different way of thinking. It also allows you to look at the programming from the different perspective.

Python installation is easy on all operating systems and you can find it in google. To install PyGTK in Windows you can use all in-one installer. There is also all-in-one installer for Mac. PyGTK is included in most Linux distributions, so you won’t need to install it if you are using Linux.


Desktop Watcher

Have you ever forgotten to lock your computer and went for a lunch? If so then you know what can happen. Your coworkers can send invitation for a party at your place to all co-workers (using your e-mail). They can also mess up with your desktop icons and much, much other fun stuff. The best solution is always lock the system. However sometimes we forget about it.

Once I was bored after work I created WinForms application, which starts playing scary sound when somebody move the mouse or push some key on the keyboard (while I am out of my desk). Usually when you want to mess up with somebody’s machine your heart rate is higher than normal (because of adrenaline that you can be caught). Then not expected scary sound can cause even heart attack.

I named my app: Desktop Watcher. It looks like that:

Desktop Watcher

When you hit Play, you get file dialog to choose some scary sound (like this) from your hard drive. Then you need to put cursor in the program area and leave your machine. You have 5 seconds for that. Every mouse move or keyboard’s key push after that will start sound playing and lock the machine. If you caught somebody the machine will be locked and sound will be playing. To quit the app you need to unlock the machine and hit ALT-F4  immediately (two keys together – because hit only ALT will cause lock screen again) or close app by mouse if you are quick hand person.

No worries that somebody close your app by ALT-F4 before he moves the mouse. If so then system will be locked anyway (but no sound will be played). You do not need to worry about it, because it means that somebody knew you prepared a trap 🙂

There is an issue that mouse needs to be in the program area to detect mouse moves. I may fix it in the future, but for now you can just hide the app somewhere (e.g. on right bottom corner):

Desktop Watcher hidden

Source (and sample scary sound) is available on github: https://github.com/jj09/DesktopWatcher.