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.

Sunday 21 April 2013

Graphic Design Using Scribus

So this is a little different from what I usually blog about but here goes...

Recently I have been tasked with a new type of work for me. I usually enjoy programming, I cope with web design as this has a little programming from time to time, especially when you get into Javascript or PHP. I actually am looking forward to a Django project that I am going to get in to soon, but that is for another time.

However, a week or so ago, a contact of mine got in touch about a client that wanted a magazine to be designed for them. They are good at the acquisition of advertising and content, but not so hot on the design parts. I agreed as the money is constant and not half bad.

However, I am not the world's best graphic designer. It isn't one of my best qualities and I will be the first to admit that. I am no artist and my enjoyment with web designs isn't in HTML/CSS but in Javascript and server side scripting. Nevertheless, I gave it a good shot.

I did copious amounts of research and I found that there are really two pieces of software that you need in order to do the graphic design for a mag. First, a publishing software, second an image manipulator. The latter is catered for in GIMP, which I use daily anyway and I actually don't mind ( although at the risk of starting a holy war I am not saying it is better than any others, it's just what I am used to). The former was something that I needed to look at. So, what GOOD publishing software can you find.

Well, I narrowed it down further to 4 basic options. They are listed below with a little synopsis:

Adobe InDesign
Adobe products are generally first in any design conversation. People really love Photoshop for image manipulation, and I can't blame them, it does a lot of the leg work for you. I have heard great things about illustrator, and I am sure that for vector based images it is great ( I rarely do this so I don't really know how this program works ). One cannot ignore Dreamweaver either, although I can honestly say that I haven't ever created anything in it as it is a little too magic for my likes.

So InDesign is of a similar ilk. It is a fully featured program that does things for you and is easy to use, although you may need some time set aside to really work out how it works in order to become proficient on it. The thing is, as with MOST Adobe products, you will spend the time wisely as you can do all that you need to do on this program.

The other benefit is that it integrates with the other professional standard programs that we have already mentioned.

The con is as always the price. If this job turns in to doing this sort of thing more often, then I will go for this, if not then I will stick with the cheaper options.

QuarkXpress
This is another program that gets a lot of great reviews from professional users. The website is clean and the software works well. However, there is one problem that I have with this program and it is similarly reflected in the above option. The price! As far as I can tell this was THE publishing software to have when you were creating mags/books etc back in the day, but then, as always, other software came along. This program HAS I believe moved with the times, but the price is still so high that you would need to be a dedicated fan not to try out the cheaper (although not by much) and more integrated InDesign.

Microsoft Publisher
If you create a professional looking magazine in this software, please comment below and tell us how much you sold your soul to the devil for. This is not a horrible software if you need to do something quick and dirty but I cannot see how you could possibly use this to do the "real" work on.

Scribus
This is an open source software and I should add, the one that I used in the end to get the first edition of the magazine up and running. The software has an adequate reference online and a reasonable interface that allowed me to work through the problems that I came across as an amateur.

There are some REALLY annoying features in Scribus that perhaps I came across as a result of using more than the others and therefore not finding the niggles in the others. One really bad feature is the text box not showing a preview of what the text will look like and being immensely buggy.

However, you over look that sort of thing when you CAN create a professional looking magazine in the time frame and you don't have to pay the earth, or even anything to use the software.

So I am annoyed with things in Scribus and it isn't the quickest way to do the job, but it is the cheapest and until the ground opens up with jobs of this nature, I will most likely stick with it. I appreciate your comments/suggestions as this is really a new area to me!


Monday 5 November 2012

Database Designer Tool

I am a very visual person. I like to see animations in a UI. I even have blogged about liking the new UI from Microsoft's latest Windows installment, why because everything is there and it's visually easy.

So that leads me on to my methodology to database design. I have mentioned before that I like to use PGSQL. Recently I have had some work to do that required MySQL. However, the database design was done already and I was touching up the code for someone else. So I needed to see the database design in a visual way. I tried to make diagrams, but when we are talking about hundreds of database tables, views and other goodies, I was just wasting time, or at least it felt like it.

So I looked online for Database designers for MySQL. I found an excellent helping from a company called Micro Olap. They have a couple of products for various database types. The ones of interest to me were the Postgres and the MySQL database designers. Including (and this was very important for me) a trial of their software.

So I downloaded the MySQL trial and within 5 minutes I had a working diagram of the hundreds of tables. How? The software included a reverse engineer feature that worked on the database that I was using. It had a lot of options but I quickly found what I wanted and ignored the rest so the best thing to do would be to have a look for yourself.

Then when it appeared you have a huge area that you can move about and see the data tables and views in relation to one another. It is similar to the database designer that you get with Visual Studio but for more useful database engines.

After a small amount of time I felt proficient enough with the software to say that I enjoyed using it. Whilst it may not be the sort of thing that you are after, especially if you prefer to see your data in a less visual way (there are people still like that out there!) but for me it answered my problem for me and I didn't have to write out all the tables by hand (which was a bonus because years of computer use have left my writing hand as out of shape as retired dosser!)

The pricing is as follows (for the products that I was interested in ):
$124.95
MicroOLAP Database Designer for MySQL (Personal/Educational license)

$124.95
MicroOLAP Database Designer for PostgreSQL (Personal/Educational license)


Wednesday 31 October 2012

Windows 8 Now that I'm using it

So it's the biggest release of Windows in my computer history. I don't really remember the leap to Windows 95, so I can't really comment on how that changed my life for better/worse. However, the leap from Vista I only remember from the smug XP sidelines, I successfully avoided Vista (although annoyingly my mother has recently inherited a Vista laptop that runs slower than a sleeping snail), and felt thrilled and excited when my hard drive crashed which gave me an excuse to move to 7. So why did I move to 8 and how have I found it?

I moved over to 8 for a couple of reasons. Firstly, I want to develop for the new metro UI. That might seem strange, but I actually quite like the neat side scrolling action, and the fact that XAML has a use outside of winforms replacement.

Secondly, I love the price of Windows 8. I got the £25 ish update from windows 7 and that is just too good. (especially since you get the pro version).

Finally, my wife said she liked the design, and that was the last straw.

So how do I get on with Windows 8. The first thing to note is that the installation and upgrade allowed me to keep all of my files and most of my applications. A few needed re-installing (such as postgres server, synergy and other service based applications). This suited me as I have not long done a full reformat so there isn't much bloat on my PC anyway. With this option selected though, it is a whole evening of your life that you are never getting back (I think Windows owes me several of those already!!).

Next up was the change in the way things work. So the new metro interface is basically a large, fullscreen Start Menu. View it like this and things don't get as bad. I use the keyboard a lot in normal computer use so using "Win Key" for opening the menu or "Win Key" + "C" for the "Charms" menu isn't a hardship for me, although I can imagine this being annoying for mousers.

The whole OS has the feel of being better on a tablet, however, this by no means stops you from using the operating system on a desktop PC. I have two monitors and this is as usual much more useful, but has it's downsides with Windows 8. The charm menu can be a nightmare to get up on the left hand monitor!

The metro UI apps are a spot unusual. you have to either ALT + F4 to close or you return to the home screen in order to "hide" them. The idea is that all of your most useful apps are "in-memory" so that you can boot them up quicker next time. The problem with this is two-fold. Firstly, in memory means that you have to have the memory, although, tbh I haven't noticed this being a problem as of yet. Secondly, to close an app, you have to either mouse to the left edge, right click on the app and then choose to close it, or do it from the new look task manager. This can be rather frustrating if you need to close an app down, there just isn't a close button in site!

Other than these few annoyances and differences, the hype about how difficult it will be to adapt is greatly exaggerated. My wife, who is no computer expert, has been using it for 1 day and already doesn't need my help to use the same apps that she was using before. My opinion is that the desktop now almost has the same feel to it that the latest Ubuntu releases have with the HUD feature, which means that even if you are coming from a non-windows background, you should find plenty familiar with the setup.

Would I recommend Windows 8 to anyone? Yes but with the condition that you keep your mind open and don't rely on other's opinions.


Sunday 19 August 2012

Emacs vs Vim vs Notepad

I like a little controversy on  a Sunday. Therefore, I thought I would spend my Sunday afternoon, curtains drawn to stop the glare, typing a little article to describe my humble opinions on the biggest question that faces the modern man.

EMACS VS VIM VS NOTEPAD!!

I have seen MANY articles from biased, dogmatic sources that claim one or the other is the pinnacle of text editing, and whilst I don't agree that it is not an important subject, I am going to try to be neither biased nor dogmatic in my analysis here.

Also a note before we get in to the nitty gritty of the article; I am BY NO MEANS a power user of ANY text editor. I have made some minor adjustments to my main text editor (which will remain nameless according to the above paragraph) but as I do most of my work in HTML, CSS , Javascript , Python and C#; most of the time I am in one of the following:
  • Visual Studio
  • Eclipse
  • Aptana Studio
I have also been known to dabble with Butterflies now and again.

I am going to tackle the editors in reverse order to the title as these are the orders that I tried them out first.

NOTEPAD
Notepad, Notepad2 and Notepad++ are what I would call traditional editors. Notepad++ has an AWESOME tabbing feature distinctly lacking in the other two, notepad 2 has debatabely better syntax highlighting and notepad is probably faster.

I like Notepad (for this section this encompasses all three above mentioned programs) as it is simple to use and requires NO brainpower which is a massive boon for someone like me.

Further more, as far as graphic user interfaces go on a text editor, I would say that any of the Notepads are far and above nicer than the other two that we will discuss today. However, they all are really just for inputting text and have no further use other than that. Notepad++ does have more in the way of plugins and probably could be put in to its own category for that reason alone, but none of the customization that is possible in Emacs is available as easily with Notepad. 

VIM
Vim was the first "keyboard only" text editor I tried. This is my own phrase for Vim and Emacs as I don't really know what to call them otherwise.

Vim is an interesting idea. You have an input mode and I forget what they call it but basically and editing mode. Switching between the two is as easy as clicking on i or esc (depending on current mode) and moving around the document can all be done using the keyboard (without going over to the arrows)

The principle idea was great for Vim, and I know people who swear by it, however, I found it immensely illogical and the learning curve just seemed to intense. I found that I was still looking up the docs after a day of using it to do simple things and I also found that looking up the docs was not fun.


EMACS

I tried Emacs when I got bored of Vim. I was put on to the idea by a blog (I forget which, sorry!) and thought that it looked like a great alternative to Vim.

The important thing for me was to not have to move over to the arrow keys and also to be able to bulk perform actions. This was easily possible in Emacs and in fact, working through the tutorial allowed me to learn and remember these commands quickly.

Which brings me to my next and possibly most difficult to explain point. I found Emacs more logical, more easy to remember and perhaps most importantly for me, more fun in documentation than Vim. As I was in the market for a quick text editor that I would invest some time in, this won me over.

However, the down side to using either Vim or Emacs is that you will need almost exclusively need to use them in order to stop yourself from getting in to bad (notepadesque) habits or from having a lot of missing characters when using normal notepad. The thing is that it is SO different using these "keyboard only" text editors, that you will find yourself as frustrated with it as if you were going from touch typing QWERTY to touch typing DVORAK. However, in a similar way there are benefits to spending the time in learning to use them wisely.

One final thing to note about the emacs editor is that it has a language (emacs lisp) that allows you turn Emacs in to much more than a text editor. However, due to time restraints and laziness I never looked deeply enough into it for it to ever be more than just a novelty.


CONCLUSION
I am still undecided as to which the best of the three are. Due to a massive amount of laziness and the fact that the IDEs that I use have only buggy support at best for EMACS I tend to use NOTEPAD more often. Is this because it is better? Honestly, I don't know, I suppose it is for me is the best answer I can give.

Vim was just not fun enough for me and I have no interest in learning any more about it unless someone can give me a non-subjective reason to. Emacs is great, however, I always felt that I was using a tool at about 1% of its potential and because of this I never really got the benefit of all the hard work that I was putting in mentally to using it. Maybe one day I will get on to using it more fully if ever I have to leave my IDEs behind. At the moment the only language I use EMACS for is C and that is VERY rare.