Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Monday, 4 August 2014

Thoughts on Swift programming language

I'm going to refer back to the last post about the state of mobile device development. I mentioned that Objective-C is the iOS default. I also stated that in my opinion, the native code is the best way to go for both iOS and Android. I have a little attachment that I would like to add to that statement, as it has bearing on the rest of this article. 

Both iOS and Android have easy ways to utilise a c++ library. The benefit is fast, multi-use libraries for things such as the DAL (data access layer). Swift has a workaround (some may argue that Android is a bit of a workaround too). But let's start at the beginning. 

Swift is a new language that Apple have released among an exciting amount of changes to their desktop AND mobile operating systems.  The syntax looks very Javascript meets Python and from the limited experience I, and all other developers outside of Apple, have, seems to be reasonably sensible in syntax too. 

First the positive. I have never really been a fan of Objective-C. I like the fact that it forces MVC as I really need to be forced in order to avoid falling into bad practices, but I really don't like the amount of time that I spend writing brackets, a practice slightly more galling than writing parentheses. Therefore, a more "C-esque" approach to the syntax was, for me at least, a welcome change. 

Apple also state that the code runs a lot faster, therefore, it seems that you are less likely to NEED to use C++ for games and other intensive applications just based on C++'s performance.

But what about the bad? There seems to be an inherent difficulty in producing a language and making it the default standard of a well used operating system: No-one knows it! Therefore, all of your developers are going to clog up stack overflow, fumble around for a while and then, unless it really is the bees knees, move back to what they were using before.

Also, if I want to change some legacy code, I need to do so in Objective-C. Now one could argue that this is what has happened to a lot of languages, I'm looking at your FORTRAN and COBOL. However, in order to really relegate Objective-C to COBOL's status, Swift would have to be such a good language, I just don't see that it makes THAT much difference. 

Another consideration is one mentioned in the prologue of this post. Objective-C is like a C++ wrapper for people with bracket fetishes. This meant that if you wanted to plug in a C++ library, then you just had to do it in the normal C++ way. However, with swift, you have to have an intermediary Objective-C header that doesn't directly contain any C++ files, otherwise Swift won't allow it. #iscplusplusdying

As mentioned at the outset, I had just found the ideal solution to the native/interpreted dilemma on mobile development, and now it looks as though I will have to "work around" the issue. This makes me an unhappy puppy. 

However, I am still overall undecided if Swift is a good idea, an abomination or something in between. Maybe any "experienced" Swift devs could comment and let me know their thoughts? 

Wednesday, 12 March 2014

State of affairs in programming for Mobiles - an opinion!

I think that we are slowly getting used to the fact that most people do most of their work now on non-desktop devices. In fact, on a recent trip away, my laptop stopped charging and I was left to look after server management and a few database bugs on nothing but tablet and phone. Thanks to 4G for that one!

However, as mobile devices (including tablets) become more ubiquitous, this means that developers are having to learn new skill-sets or broaden existing talent. The following information is just a quick summary of information and opinions that I am forming with regard to mobile development.

Choices
When you take on a new project for mobile devices, the first thing that you are likely to have to decide from a programmatic point of view is whether to have a single code base or to write more natively for each device.

To explain: iOS uses the increasingly popular Objective-C as a native language. Whereas Android uses Java. I'm not sure about Blackberry as I have never had any one ask for an app, however, it seems as though c++ would probably be the language of choice for that. The benefit is that you can write straight for the intended operating system and will have full access to the SDKs and APIs that make development easier on those platforms. At present, for the scale of apps that I develop, this is the weapon of choice for me.

Alternatively, you can write non-native code that accesses the APIs indirectly. Perhaps the best example that caught my eye was Xamarin, primarily because it allows you to write code in c#. The obvious benefit is the re usability of code. The write once, use anywhere syndrome that made Java popular. Other companies do have similar libraries (another notable c# entry is DevExpress).

So the question is, why do I still use native code rather than cool 3rd party frameworks that allow you to write a common set of libraries?

Firstly, cost is a big thing. A lot of these libraries ask for large lump sum payments and/or subscriptions. When developing, I am rather scrooge like and will try to get anything that I can for free before I go to the paid option.

Secondly, I am quite thick and I found that with the small amount of time that I have spent on learning native languages vs learning c# for Xamarin or DevEtreme, I actually progressed quicker learning a new language. I find that the Data Access and common tasks are far more simple to learn from the docs of the native languages and I really love the MVC way that Objective-C utilizes! (but that's for another post me-thinks).

Finally, I have bad experiences with write once libraries. Without going too deeply into the reasons (again another post's job), I have found that there are a lot of issues and bugs that you simply don't get in native libraries that transfer to non-native libraries. This is certainly true of desktop equivalents and I have found similar sentiments regarding the mobile libraries that has put me off for now. What I really don't want is to be promised a write once scenario only to have to continually put "if" statements or other conditional branching for each operating system. I actually would prefer to write it all again (but with the logic already in mind) than to do that.

Again, this post is highly subjective and some of you may find different scenarios work for you than what I have outlined above. If you have any comments, please feel free to comment below and tell me where I am wrong.

Saturday, 3 August 2013

Writing a silent updater in c#

So recently I have been working on some software for windows for a company here in the UK. The software does lots of cool stuff including taking orders and products from Quickbooks and syncing with a website.

One of the things that I wanted to do, was to avoid having to release an update individually to each user that has the software installed (this could be quite a few down the line). Therefore, I thought that I would write a simple auto-updater that works behind the scenes. In the making of it there were a number of new tricks that I learnt that I thought that I would share with the world. As always, if you see a security/efficiency issue, please let me know either in the comments or you can contact us direct:
daniel@casserlyprogramming.com

How it works
The basic design was that a windows service would run and check regularly, whether or not the software was up to date. If it is not, then it downloads the latest version and overwrites the needed files. As this is a fairly small project without massive files (and is unlikely to be such), this approach is acheived in the following way:

  • The service has a timer. The timer runs every 5 mins.
  • If the software is open, we don't do the update (point 1)
  • There is a version stored on a database that is accessible from the service. The local version is stored in an ini file. If the versions don't match we perform the update. 
  • We download a zip file which is the files that have changed since the last update (with the version number as the name of the zip) (point 2)
  • Then we unzip and overwrite the files in the installation directory of the program (the service exe is shipped in the same directory so that we can unzip the files straight to the root of the program. (point 3)
  • Then we update the local version number and log the update (I also send myself an email to state that <this computer name> has updated to <the version number>). 
All that the software itself does is on load it checks if the service is installed. If not it installs it (which in turns starts the service). If it is installed it checks if it is running. If not it starts the service. Simples!

Point 1 - Checking that the software is running
I found some code that seems to work fairly well and finds if any Process is running:

//--------------------------------------------------------------------------------  public bool IsProcessOpen(string name)
{
     foreach (Process clsProcess in Process.GetProcesses())  
    {
       if (clsProcess.ProcessName == name)   
      {
         return true;   
      }
    }
    return false;
}

Then I pass in the process name for my software to check that if it is running.

Point 2 - Downloading Files
This was something fairly new to me. However may come in handy. In order to do this (I presume there are multiple ways as usual) simply, the following code will help:
using (WebClient client = new WebClient())
{
   client.DownloadFile("http://urltozip.com/" + new_version.Replace(".", "-") + "-EXE.zip", new_fn);
}

Point 3 - Unzipping files
I found an excellent library for using standard zip files in c# (unlike python the standard zipping/compressing is not really that useful IMHO).
http://dotnetzip.codeplex.com/

using that all I needed to do was the following to get my files out of the zip:

 using (ZipFile zip = ZipFile.Read(new_fn))     
{
           foreach (ZipEntry ent in zip)         
              ent.Extract(".", ExtractExistingFileAction.OverwriteSilently);    
}

A few points that are important here:

  • The using is very important. We need to dispose of the ZipFile object (according to the readme). 
  • The "." is the directory we want to unzip to. In my requirements this was the same directory as the zip. An empty string will cause an error. 
  • The second parameter is an enumeration. I chose the silent overwrite for obvious (I hope) reasons. 
Conclusion
This only took me a few hours of coding and Googling. Therefore, we will see how it stands the test of time. I imagine that there are more elegant ways of doing a lot of this and this will work for my requirements much better than probably most other software.

Again, if you have any comments, please feel free to let me know.

Tuesday, 3 July 2012

Equals or ==?

So Android is pretty ubiquitous now. New tablets/phones coming out with the version 4 upgrades and awesomeness. I personally love my Android phone. No, it's not expensive, but I love it!

However, this is where I get to moan. I have never really touched Java before Android came out. Some people swear by it, I swear at it! It's not that Java is an aweful language, in fact there are some really nice features. However, from a C# point of view it is somewhat like learning Polish after learning Russian.

You see the slavic languages are very similar. The have a similar verb conjugation and many similar verbs, and then you get to the important bit, the verb that is the difference between like and love and it lets you down and changes. (Russian love transliterated is "lubit" in Polish lubic is to like).

The same thing happened with Java. I'm feeling confidant in the fact that I can write code without looking up syntax just because it's SO similar to C#. So much so that when i evaluated two variables with a

     if(var1 == var2) { // Do Something... }

statement, saw in debugging that they had the same value I expected that the // Do Something... code would run. WRONG! Turns out that the == in Java is COMPLETELY different to C#!

"EEEJIT!" you say. "Java is a better and older language than C#"

"No need to be rude!" Say I "C/C++ is an even older an more widely known langauge than even Java"

So how do we get around this evilness? Why does this happen?

Java-Samples states : "the equals( ) method compares the characters inside a String object. The == operator compares two object references to see whether they refer to the same instance"

So the equals() method was what I needed. Tbh I had not been so dissapointed by a language inconsistancy since the lack of switch in python. I look forward to comments and suggestions (clean ones please) about what I'm missing in Java that makes it better than either C# and/or Python. 

Tuesday, 1 May 2012

Android Programming - Yes I know it's Java!!

So this week has lead to me getting to that point in my interminable list of projects to do where I finally bit the bullet and started doing some development for Android.



The first thing that struck me with Android development is Java. I could not believe that I was being forced in to such an unusually bloated language for such a small device. However, I instinctively feel that the guys behind it must have a much better undestanding than me so, let them get on with it. The interesting thing is that it is not a standard JVM but rather runs on the Dalvik VM.

So I decided to go for the new kid on the block Intellij Idea as an IDE. I looked into the Eclipse, and didn't much like it. I installed and almost immediately went with Intellij and haven't looked back. I realize this is subjective, however, I don't care! ;-)

The second thing I learnt was that you need to have a kettle handy for the first time you run the emulator. Closely related is the fact that you never want to close the emulator until you are sure that you are done debugging. This is somewhat due to the fact that the time it takes for the emulator to load the first time is comparable to my grandmother crossing the road, walking up the stairs and putting a brew on for me!

But when you get past all of that, I was really impressed with the layout tools, the xml resources and how easy they were to use, the simple differences between activities, services and broadcast receivers and how they all fit together with the Java language. (it nearly turned me to Java for desktop apps but not quite!) Everything by default is well layed out in the various folders and I feel that I automatically know where I should look for changes to be made after only a day looking into it, and I am no master by any stretch.

A few more interesting features took my eye (and it is possible that these are IDE specific):

[1] Awesome debugging and logging in the Android tab
[2] Git support  (oh yes!!!!)
[3] The DDBM (Dalvik Debug Monitor) has Emulator control where you can call the phone. Great for the app I am writing and also for feeling that you have friends without having to talk to them on the phone!!
[4] Good support network. I can't belive that in the relatively short time that Android has been about, I can find someone else somewhere who has done, is trying to do, will do something that I am trying to do and documented it online (go to love Google for that). This is something that even Python and C# have not yet managed despite the slightly longer life they have led.

So all in all, I really like programming for the Android and would recommend it to anyone! Programming is fun again!! Actually it was always fun but now we have an emulator which means that debugging is more interesting for my long-suffering wife :-)

Sunday, 1 April 2012

Welcome to my blog

Hi all. This blog is going to be all about programming and other aspects of life that are touched by computer use. I am not a programming master and as such I often come across new things that I learn in my travels. As I do so I will share them here and you all can get involved too.

One thing that I feel passionate about in the sphere of programming is the place of Open source and community software. Therefore, if I produce a tool, library or other set of code that I think will be useful, I will definately share it on either sourceforge or github (or both if I am feeling energetic.)

Contact me for more information or for a full CV!