Home
Store
Support
Company
Blog
Dev

The Named Argument

Thanks to the iPhone and the growth of the Mac there are a lot of people now interested in Objective-C and Cocoa. Many of these developers come from other backgrounds such as Python, Ruby, C#, C++, Java etc, but Objective-C is quite a different beast to those languages.

Of course there are quite a few similarities. It shares the C heritage of C++, it is highly dynamic like Python and Ruby. However, the biggest difference between Objective-C and most other languages is how method names and arguments interact.

At first glance a lot of developers coming from other languages think that they are simply named arguments which is wrong, VERY wrong. This is one of my pet peeves about new Objective-C developers, and every time I see someone talking about named arguments in Objective-C I always feel a need to correct them. But if they aren't named arguments then what are they?


Interspersed Arguments

The arguments aren't named, but interspersed with the method name. For example, a method in another language may be obj.foo(namedArg1=bar, namedArg2=possum), so its method name is foo. In Objective-C a similar method may be [obj foo:bar with:possum]. In this case the method name is foo:with:. So the arguments aren't named, they are mixed in with the method name.

There are some key differences between named arguments and interspersed arguments:

1) Named arguments' names are not part of the method name
2) Named arguments can be re-arranged
3) Named arguments are often optional

None of these hold true for interspersed arguments. This is why I've seen quite a few people complain about Objective-C's "named arguments" not being very flexible. When you realise they aren't named then things get much easier to understand. As with everything in Cocoa and Objective-C, if it is different to what you are used to, then there is likely a very good reason for it being that way.


Examples

So it would make sense to show some examples comparing named and interspersed arguments. So lets take a common Objective-C method:

[@"A string" compare:@"B string" options:NSCaseInsensitiveSearch range:someRange];

And now lets convert it to a language like Python which has named argument, treating the arguments as named arguments:

"A string".compare("B string", options=NSCaseInsensitiveSearch, range=someRange);

Not a big difference at first, but lets try some variations:

"A string".compare("B string", range=someRange, options=NSCaseInsensitiveSearch);
"A string".compare("B string", options=NSCaseInsensitiveSearch);

In Python those are both the same method as the first one. However, in Objective-C, re-arranging the arguments or removing them would result in an entirely different method being called. While in the Python examples the method is called compare() in the Objective-C example it is called -compare:options:range: which is a big difference. If we correctly treat the arguments as interspersed then the Python example becomes:

"A string".compare_options_range("B string", NSCaseInsensitiveSearch, someRange);

Of course Python doesn't support interspersed arguments so they are all attached at the end, but basic rules are the same. Hopefully this has helped quite a few Objective-C newbies to understand one of the many differences between it and other languages they are used to, but if you have any questions then leave them in the comments.

(4) Comments

Posted on 05/31 at 10:29 AM in Coding



Going Full Time

So I've done it. I said in November that I wanted to be able to go full time with M Cubed in about 7 months. 7 months later I'm going full time. It's been a long time coming but I have finally finished my full time education and can now concentrate fully on M Cubed.

M Cubed has been a part time venture ever since it was founded back in 2005. It always came second to exams and assignments and homework. Because of this releases have been far and few between and often come in spurts when I've had a lot of free time. In the past 3 and a half years I have released just 10 major updates to apps. I'm wanting to seriously improve on that by getting major updates to all my current apps out by the end of the year, and possibly a new app or two.

With all the extra time I will have now, you can expect to see a lot more open source efforts from M Cubed as well as more blog posts discussing various technical things. It will be nice to be able to dedicate time to give back to the community that has helped me get to this point.

And finally, there is some incredibly huge news still to come, all will be revealed on the 1st of July, so watch this space.

(0) Comments

Posted on 05/28 at 06:42 PM in General



Success != Being Rich

I don't usually write anything on here that may be related to politics (that's usually left to my twitter account) but there is something I heard today that irked me enough to write a blog post on it. It relates a lot to running a business but also to life in general so hopefully it will be of interest to those who are reading it.

For those who don't know, I'm based in the UK. Yesterday the UK government announced the budget for the next year. As well as hearing about how we're all basically doomed the government announced that there will be a new 50% tax band for those earning over £150,000 a year. This means for every pound you earn over £150,000 a year, half of it will go to the government to pay for various public services.

Of course there has been outrage from many of the 1.5% of the population who earn over £150,000 a year and this is partially understandable. Nobody likes paying taxes, but they're a necessary evil and help to pay for things such as health care, roads, schools, parks, refuse collection, police, fire services, defence and many other crucial services. Unfortunately some of the rich feel they're being punished for being successful.


Perceptions of Success

The BBC News had a businessman on their channel to talk about the implications of the tax rise. He felt it was unfair that the successful were being punished for their success. Of course what he really meant was "rich". There is a common perception that in order to be successful you have to be rich. To me this is incredibly flawed. A CEO of a failing company can be incredibly rich but the owner of a small, but successful business may not be rich (thought they probably aren't poor). Yet for some reason the CEO is seen as more successful in life.

Its this perception that leads to many people's desire to be rich. They want to be seen as a success. The problem is it is wrong. Taxing people 50% on their earnings over £150,000 isn't taxing the successful. It isn't really taxing the rich either. It is taxing the greedy.


Massive wages = greed

OK, so that is a little unfair. Some people need bigger wages. Perhaps they're in a career where they can't work until they're 65. No-one would have any qualms with police officers, fire officers, sports stars, soldiers, physical labourers etc earning higher than average per year. Their wages may go down after they are required to change career or forced to retire because they are too old, or have picked up an injury caused by their work, so earning more while they're in their prime makes sense.

I'm also not advocating everyone should be paid the same wage. Those who are highly skilled should be paid more then average. Those who put themselves in danger and/or save lives should be paid a hell of a lot more then average (and also a lot of respect). A varying pay scale is perfectly fine. It is also a case where you may need to earn more depending on the number of people dependant on you (eg children) or where you live (eg London is a much more expensive place to live than Blackburn).

The problem is with those who earn a lot of money each year, more than £150,000, and then spend it on themselves. These are often the people complaining the most about higher taxes for the rich. Of course not everyone who earns that much money is greedy. Some people earn a lot of money but give a huge amount of it away to charity. Nobody could call those people greedy (indeed I believe all money given to charity should be fully tax deductible to encourage more to give to charity).

But those who have a lot of money left over after they have given to charity and paid for the essentials that everyone needs are just being greedy. They'll likely buy themselves a much bigger house they need, or an extremely pricey sports car etc. Things they don't need with a huge amount of disposable income. Things to signify "success".


The Right Thing To Do

So if you are earning that much money, you really have no right to complain. If you are running a successful business and taking £150,000 a year in wages or more then you're being greedy. You could give yourself £50,000 a year and still be incredibly well off. You could have a large house, 2 very nice cars, go on holiday abroad once a year etc.

But what about the other £100,000? Well that could be given to charity. Think about how much good you could do with £100,000. Or how about hiring some more staff. You could hire three people for £33,000 a year. That's a pretty decent wage and you've just helped lower the unemployment figures by 3 people.

The reason that those who earn a lot of money are taxed at a higher rate is that the money they have being taxed at that rate is disposable income. They don't need it, they simply want it. That money can be used for a lot of good and improve the lives of a lot of other people.

Success really needs to be redefined, or rather it's actual definition needs to be reclaimed. Success should be based on how well you perform, not on how much you earn.


Businesses vs Individuals

Businesses are slightly different to individuals. If a business earns a large profit then it's not necessarily a bad thing. In fact that is success. Of course how they use that profit is key. They may give all their employees a share of it, or invest it in research and development. They may save it in order to protect themselves against times when they make a loss or for future plans such as expansion which will create jobs.

Of course, that doesn't mean businesses should be entirely immune to criticism either. If they do make a huge profit they should also not complain about it being taxed. The money that gets taken away as tax goes towards many things that help them as a business prosper, and also in improving the lives of their individuals.

Tax money that goes into improving schools helps provide more skilled workers for the business. Tax money that goes into transport helps the business move their goods and workers around. Tax money that goes into communications infrastructure helps the business expand while being able to keep track of everything. The taxes being taken from a business's profits aren't really a loss of money, but an investment in the business.


Success = Doing Well

As I said earlier, taxes are a necessary evil. But higher tax rates on higher earners is not taxing the successful. There are plenty of people earning under £150,000 who are successful, to say otherwise would be saying 98.5% of the population are failures.

Success as a word needs to be reclaimed to mean doing well, setting out goals and meeting or surpassing them. If we can do that then maybe we can see society becoming more equal and those who do earn a lot of money choosing to help others with it, rather than themselves.

(16) Comments

Posted on 04/23 at 03:15 PM in General



The Obligatory NSConference Post

So NSConference has been and gone. This was my first Mac conference so I've not really got anything to compare it to, but it was the most interesting and enjoyable few days I've had all year. Mac developers are often quite isolated and don't get to meet up very often, at least not in large groups. This was the first time I've met so many Mac users in one place and it was a great experience.


The Conference

The talks were great and I picked up some great tips and learned about some cool technologies that I'll be looking into more in the future. It is often the little things you pick up from in talks that really stick with you and can help you the most. This was helped by the last session where the speakers had to give a few quick tips over 3 minutes after being pulled away from an application design competition they were working on.

I was lucky enough to be given a short lunchtime slot to talk about accessibility. I made the talk, not to discuss technical issues, but to emphasise why accessibility is important and should be top of our agenda as developers. It seemed to really resonate with those in the room, with many saying they were going to make the pledge to make their apps fully accessible by the end of the year. Those who didn't were also very committed to accessibility but many didn't want to make the pledge as they were unsure they would be able to fulfil it before the end of the year. At the very least, it brought a very important topic front an centre to a large chunk of the Mac developer community.

The conference was held at the University of Hertfordshire in Hatfield on the relatively new de Havilland campus. The facilities there were great, with the restaurant (which served excellent food for breakfast and lunch), bar and lecture theatre where the talks were held all within a short walk of the accommodation.

Of course, being a university campus the accommodation was decidedly student oriented, though still being a student it wasn't a problem, plus besides the few moments spent sleeping there wasn't much time spare to be spent in your room.

Now all this wouldn't have been possible without the time and effort put into organising and running the conference by the staff. Scotty and Tim did a great job and managed to put on an amazing event which everyone who went is thankful for. And we can't forget Dave, who dealt with many of the technical aspects of the conference and Ben, who sat patiently outside at the registration desk for hours on end. These guys worked incredibly hard with very little, if any, money in payment for their time and effort and a lot of people now owe them a great debt of gratitude. Here's hoping for an NSConference 2010. If there is one you can bet I'll be there.

One important thing that was mentioned at the conference but not linked to, was my unofficial attendees list. If you went to NSConference make sure you add yourself so others can know you were there!


The Badge

Now, as all the praise is out of the way, lets get onto what went wrong. (Actually, one more bit of praise. The badges we received were incredibly well designed and clear and it was obvious a lot of thought had gone into them. Anyway, back to the failing).

It turned out I was the very first person to register for the conference (I feel like I should have had a golden badge with "#1" written on it, but oh well) and so my badge ended up being the test badge. Scotty and Tim printed out loads of badges with my details on until they got it right. Once they'd perfected mine they printed out everyone else's.

Then it comes to the conference and they pull out all the badges to put into their holders. Out of over 100 badges the only one they couldn't find was mine, the one which they had done the most copies of over the past few weeks. So of course starts a frantic search for the badge, which is eventually found at the bottom of a waste paper bin all crumpled up.

So here is my badge, all crumpled up, next to all the pristine flat badges of the other attendees. So what is the solution to this? Well they pull out an iron (who knows why they had an iron) and start to ponder whether they should iron the badge flat. Thankfully this whole thing was caught on camera by Alasdair Allan (see his flickr set for the conference here) for all the world to see, so I shall leave you with 3 orange men, an iron, a hair dryer and my badge:

Scotty, Tim and Ben wondering how to flatten my badge. Photo Credit Alasdair Allan
Scotty, Tim and Ben wondering how to flatten my badge. Photo Credit Alasdair Allan

(6) Comments

Posted on 04/21 at 02:38 PM in General



Page 1 of 21 pages  1 2 3 >  Last »

About

This is the weblog of M Cubed Software. If you'd like to know more about us head to our about page.

Software

Code Collector Pro

Snippets++;


Minim

Manage your creativity


Lighthouse Keeper

The best issue tracker on the web, now on your Mac


Misc


 Subscribe (Atom)

Monthly Archives

  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007


© 2006-2009 M Cubed Software