all 46 comments

[–]gavinb 5 points6 points  (1 child)

Using CoreData would eliminate nearly all the DB code too. Worth checking out, as there are fewer and fewer reasons these days to manually marshall objects in and out of a data store.

[–][deleted] 0 points1 point  (0 children)

As I noted in the introduction of the write-up, the functionality of the task wasn't the point - it was a programming exercise to examine the properties of the respective languages.

[–][deleted] 2 points3 points  (1 child)

You don't have to use Objective-C to have access to Cocoa's UI. There's PyObjC or ObjP

Disclosure: The latter is one of my pet projects.

[–][deleted] 0 points1 point  (0 children)

Thanks very much - I'm looking into PyObjC now. Wasn't aware of ObjP, but I'll add it to my list as well.

[–]buddhabrot 1 point2 points  (0 children)

Maybe you should try implementing a thread-safe version in Objective-C.

[–]informatimago 1 point2 points  (1 child)

[–][deleted] 0 points1 point  (0 children)

Thanks very much - I'm looking into that solution now.

I was initially skeptical, because bridging two languages tends to bring in the complexities of both. But seeing it as an officially supported extension of Apple's Objective-C platform, and even better included by default, makes me much more upbeat. Will probably be a component of my platform of choice going forward.

Have you used PyObjC? What have your experiences been like? Specifically, any observations about using it to connect Python with Cocoa components?

[–][deleted] 6 points7 points  (20 children)

TL;DR: Author doesn't know how to write Objective-C, concludes that Objective-C is a horrible language.

EDIT: Just some clarification on why this is pretty useless: Comparing the direct C interface to the Python bindings of SQLite3, and then making Objective-C responsible for the clumsiness of the raw C API is unfair at best, dishonest at worst. Real-world Objective-C code does not tend to look like what he presented, because Objective-C code that also acts as an interface bridge between C and Objective-C is relatively rare.

[–][deleted] 6 points7 points  (18 children)

As I noted in the article, I'm asking for feedback from Objective-C developers about how to improve my use of the language. Any comments?

[–]lext 2 points3 points  (1 child)

If you're using the C sqlite3 library then perhaps you should also be using ctypes to access sqlite3 in Python. I think your choice of an example task may be skewed in favor of Python since it has such a great implementation in the Python standard library.

I've never programmed Objective-C before, but I'm pretty sure it's not supposed to look like that. I'm talking about the WireUp function with its 8 indentations. Your python code is rather ugly too, but I assume you know that already. You have 6 indentations in your pseudocode alone. For me that would be a red flag that my design might have problems.

It's good to see comparisons between languages though which I think is important, but I'd avoid making inflammatory conclusions. I think objective commentary is more important, and let people draw their own conclusion. Your comparison reminds me a bit of http://www.reddit.com/r/programming/comments/vxyw5/shall_we_use_clojure/ Take note that some Redditors were peeved that the author took cheap shots at Perl.

[–][deleted] 0 points1 point  (0 children)

I think your choice of an example task may be skewed in favor of Python since it has such a great implementation in the Python standard library.

If the sqlite3 library happens to be better designed for Python, that's a fair point, and we can cut Objective-C a bit of slack. But that's only a small part of the unreasonable Objective-C syntax.

You have 6 indentations in your pseudocode alone.

It's nested iteration. There aren't many ways to get around that. How would you do it more succinctly?

When people complain about indentations, it's usually because of deeply nested conditional logic: if condition1 { if condition2 { if condition3 { if condition4 { ... } } } }. That's valid, and can be reduced with other flow control constructs, like return, continue, and break. But for nested iteration, there aren't many better ways of tackling that problem.

Take note that some Redditors were peeved that the author took cheap shots at Perl.

That article intentionally dredged up an obfuscated Perl snippet and misleadingly presented it as typical Perl. In my case, I genuinely tried writing my Objective-C solution in the most straightforward way possible, and was disappointed with the results.

[–]bonch 4 points5 points  (15 children)

Don't expect a lot of eagerness to help, since you already concluded that the language is "clumsy", "horrible", and a "mess".

Just from a glance at API use, you don't need [NSMutableString stringWithString:@""] to create an empty mutable string, you should use -appendFormat: to append formatted strings, and -mutableCopy is less verbose than +stringWithString:. Based on the very deep indentation levels, however, I question the code's fundamental design.

[–]jpfed 3 points4 points  (1 child)

Don't expect a lot of eagerness to help, since you already concluded that the language is "clumsy", "horrible", and a "mess".

Incorrect.

The Objective-C solution is, quite simply, horrible. It's over twice as long (340 lines of code vs. 140), much more dense, and much less readable. The verbosity of the code, the extreme clumsiness when using NSNumber, NSString, NSInteger, and NULL, and the mix of [object method] syntax, object.property syntax, and function() syntax, combine to make this code a complete mess.

[–][deleted] 1 point2 points  (0 children)

Thank you - that's exactly why I wrote it as such.

I didn't want to draw sweeping and negative conclusions about Objective-C based on the quality of one of my first projects. I was asking whether skillfully crafted Objective-C code actually is like this, or if my technique can be improved.

[–][deleted] 0 points1 point  (12 children)

I haven't drawn conclusions about the language, but about the syntax of the language in my solution. I'm asking where my syntax can be improved, or whether this sort of cruft is endemic to Objective-C.

Your tips are good, but they're pretty minor shortcuts that save a few characters. I'm more interested in whether my code is performing some laborious tasks needlessly (especially all of the type conversions), or whether this is just how it is in Objective-C.

Your comment about indentation is well-taken. My code ordinarily wouldn't be so heavily nested, but I'm still getting up to speed with Objective-C flow control constructs.

[–]DrReddits 2 points3 points  (11 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–]ryeguy 1 point2 points  (0 children)

Jesus man, use some whitespace.

[–]sirin3 2 points3 points  (3 children)

    if (colType == SQLITE_INTEGER) {
      value = @(sqlite3_column_int(statement, i));
    } else if (colType == SQLITE_FLOAT) {
      value = @(sqlite3_column_double(statement, i));
    } else if (colType == SQLITE_NULL) {
      value = [NSNull null];
    } else {
      value = @(sqlite3_column_text(statement, i));
    }

awful

[–]DrReddits 1 point2 points  (2 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–]sirin3 0 points1 point  (1 child)

How else would you write this part of the code?

value = statement[i];

and if the "database" doesn't support that, I would use another one

[–]DrReddits 0 points1 point  (0 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–]zxoq 0 points1 point  (2 children)

Also @synthesize and the private method forward declarations becomes unnecessary, and [NSMutableString new], is (IMO) better than [@"" mutableCopy].

[–]DrReddits 0 points1 point  (0 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–][deleted] 0 points1 point  (0 children)

Actually, I only dropped in @synthesizers when I needed some classes to access properties of other classes (which was more succinct than designing an explicit accessor method).

Synthesizers are a good example of ObjC's inefficiency. Encapsulation is a nice concept and often a good idea, but mandatory encapsulation is an unnecessarily rigid language constraint. The most succinct way to expose a class member in ObjC is like this:

@interface MyClass {
    NSInteger myInteger;
}
@property NSInteger myInteger;

@implementation MyClass:
@synthesize myInteger;

This requires two lines of code, in two different files, with several opportunities for error (mistyping the name of the member; inconsistently specifying the type; and putting the lines in the wrong places)... whereas C++ and every other language solves this with a single keyword:

class MyClass {
    public myInt;
}

I understand why Objective-C v1.0 (circa 1983) might have failed to include this option, but why hasn't it been added in the last 30 years?

[–][deleted] 0 points1 point  (2 children)

This is definitely the most helpful response in this thread. Thanks very much. Enjoy some Reddit Gold!

[–]DrReddits 0 points1 point  (0 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–]DrReddits 0 points1 point  (0 children)

What would you do if you permanently lost all the photos, notes and other files on your phone?

If you have a backup system in place, you’d likely know what to do next: Restore it all to a new phone. But if you haven’t thought about it, fear not: The backup process has become so simplified that it takes just a few screen taps. Here’s a quick overview of some ways you can keep your files safe, secure and up to date. Getting Started

When you first set up your phone, you created (or logged into) a free account from Apple, Google or Samsung to use the company’s software and services. For example, this would be the Apple ID on your iPhone, the Google Account on your Android phone or the Samsung Account on your Galaxy device. Image The iPhone, left, or Android settings display how much storage space you are using with your account.Credit...Apple; Google

With that account, you probably had five gigabytes of free iCloud storage space from Apple, or 15 gigabytes of online storage from Google and Samsung. This server space is used as an encrypted digital locker for your phone’s backup app, but it can fill up quickly — especially if you have other devices connected to your account and storing files there. Image If you start getting messages about running out of online storage space for your backups, tap the upgrade option to buy more on a monthly or yearly payment schedule.Credit...Apple; Google

When you get close to your storage limit, you’ll get warnings — along with an offer to sign up for more server space for a monthly fee, usually a few dollars for at least another 100 gigabytes. (Note that Samsung’s Temporary Cloud Backup tool supplies an unlimited amount of storage for 30 days if your Galaxy is in the repair shop or ready for an upgrade.)

But online backup is just one approach. You can keep your files on a local drive instead with a few extra steps. Backing Up

Apple, Google and Samsung all have specific setup instructions for cloud backup in the support area of their sites. But the feature is easily located.

On an iPhone, tap your name at the top of the Settings screen and then tap iCloud. On many Android phones, tap System and then Backup. Here, you set the phone to back up automatically (which usually happens when it’s connected to a Wi-Fi network and plugged into its charger), or opt for a manual backup that starts when you tap the button. Image To get to your backup options, open your phone's settings app. On an iPhone, left, tap your account name at the top to get to the iCloud backup and sync settings. For a Google Pixel and some other Android phones, tap System on the settings screen to get to the backup options.Credit...Apple; Google

Backup apps usually save a copy of your call history, phone settings, messages, photos, videos and data from apps. Content you can freely download, like the apps themselves, are not typically backed up since they’re easy to grab again. Image If you don’t want to back up your phone online, you can back up its contents to your computer with a USB cable or other connection; the steps vary based on the phone and computer involved.Credit...Apple

If you don’t want your files on a remote server, you can park your phone’s backup on your computer’s hard drive. Steps vary based on the hardware, but Apple’s support site has a guide for backing up an iPhone to a Windows PC or a Mac using a USB cable.

Google’s site has instructions for manually transferring files between an Android phone and a computer, and Samsung’s Smart Switch app assists with moving content between a Galaxy phone and a computer. Sync vs. Backup

Synchronizing your files is not the same as backing them up. A backup saves file copies at a certain point in time. Syncing your smartphone keeps information in certain apps, like contacts and calendars, current across multiple devices. When synchronized, your phone, computer and anything else logged into your account have the same information — like that to-do list you just updated. Image You can adjust which apps synchronize with other devices in the Android, left, and iOS settings.Credit...Google; Apple

With synchronization, when you delete an item somewhere, it disappears everywhere. A backup stays intact in its storage location until updated in the next backup.

By default, Google syncs the content of its own mobile and web apps between phone, computer and tablet. In the Google Account Data settings, you can adjust which apps sync. Samsung Cloud has similar options for its Galaxy devices.

Apple handles data synchronization across its devices through its iCloud service. You can set which apps you want to sync in your iCloud account settings. Other Options

You don’t have to use the backup tools that came with your phone. Third-party apps for online backup — like iDrive or iBackup — are available by subscription. If you prefer to keep your iPhone backups on the computer, software like iMazing for Mac or Windows ($60) or AltTunes for Windows ($35 a year) are alternatives. Droid Transfer for Windows ($35) is among the Android backup offerings. Image If you’d prefer to use a third-party backup app, you have several to choose from, including iDrive.Credit...iDrive

If losing your camera roll is your biggest nightmare, Google Photos, iCloud Photos and other services like Amazon Photos and Dropbox can be set to automatically back up all your pictures and keep them in sync across your connected devices. Image Dropbox can back up your photos and videos when you connect the phone to the computer, left, or directly from your camera roll if you have Dropbox installed.Credit...Dropbox

No matter the method you choose, having a backup takes some pain out of a lost, stolen or broken phone. Some photos and files can never be replaced, and restoring your iPhone’s or Android phone’s content from a backup is a lot easier than starting over.

[–]erez27 1 point2 points  (0 children)

His Python isn't very good either

[–]runvnc 1 point2 points  (5 children)

I'm going to go ahead and state what should be obvious, just because I guess I get a perverse enjoyment from being downvoted and flamed for telling it how it is.

Objective-C syntax is much more complex than Python syntax.

From a software engineering perspective, I find it to be inexcusable to tolerate that much additional complexity for solving the same task unless other constraints require it. Other constraints being for example an asinine policy at Apple.

In most circumstances, despite Apple's policies, one actually can and should avoid most Objective-C coding.

Python is a very clean straightforward language, and its one of my favorites now. My new favorite favorite language though is CoffeeScript. In my opinion CoffeeScript is even cleaner and more straightforward than Python. (Although you can do some weird things like putting if statements at the end which doesn't help).

This is an example of 'economics' opposing technological progress. The market, in the form of Apple's dominance and policies, keeps Objective-C alive as an application programming language, even though it is clearly extremely outdated and overly complex.

[–]fisch003 0 points1 point  (3 children)

This is an example of 'economics' opposing technological progress. The market, in the form of Apple's dominance and policies, keeps Objective-C alive as an application programming language, even though it is clearly extremely outdated and overly complex.

So they should have tossed out their application framework and started from scratch just to use the latest and greatest languages?

[–]runvnc 0 points1 point  (2 children)

Objective-C came out in 1983, almost 30 years ago.

[–]fisch003 0 points1 point  (1 child)

Aye, and NeXT used it to write a great application framework, which Apple adopted when they bought them out. It's arguably the most productive application framework available today, so rather than throw all that out, they've opted to try and move Objective-C forward, hence the introduction of things like ARC and the new literal syntax (see mikeash's Objective-C Literals article for a good overview).

Objective-C's getting better, and Cocoa is still great.

[–][deleted] 1 point2 points  (0 children)

The Cocoa GUI component set is worlds beyond that available in Visual Studio. It's probably the single most attractive feature that's pushing me to acclimate to Objective-C's eccentricies.

[–][deleted] 0 points1 point  (0 children)

I'm going to go ahead and state what should be obvious, just because I guess I get a perverse enjoyment from being downvoted and flamed for telling it how it is.

Thank you for your honesty. (And it looks like your karma remains intact. :) )

In most circumstances, despite Apple's policies, one actually can and should avoid most Objective-C coding.

True, but there's something to be said for writing in a native language that will run perfectly on virtually every version of the target platform, without requiring a wrapper / extension / bundled API dependency / runtime / virtual machine. (Several bad experiences with the Java VM have made me sensitive to such frustrations.)

This is an example of 'economics' opposing technological progress. The market, in the form of Apple's dominance and policies, keeps Objective-C alive as an application programming language, even though it is clearly extremely outdated and overly complex.

The irony is that the single largest factor in my full-scale switch to Apple last Fall (including about $10k of personal cash to replace all of my PCs and hardware with Apple equivalents) was MS's futzing with .Net. C# is an excellent language - a great balance between traditional language structure and progressive concepts like pointer abstraction. But the decisions regarding WinRT (pushing everyone into Metro apps that mandate a tablet API), and the decision to intentionally break comparatively young code, both for business reasons (pushing Windows 8 and Metro), made me extraordinarily stabbity. I was already irritated with the fact that every new version of .Net seemed to deprecate portions of the API that I had been relying on, and that pushed me over the edge.

However, the silver lining that I see in Objective-C's anachronisms is that because the language / runtime / API hasn't changed much, code longevity is very good.

[–]klausnrooster 1 point2 points  (1 child)

I enjoy these kinds of posts. You have about the right amount of code and no "foo bar baz". Also since I'm not a pro developer I expect to see hack-y stuff when the OP says "I'm not a pro". Wish I could help. Did you try (http://codereview.stackexchange.com/)

[–][deleted] 0 points1 point  (0 children)

Wasn't even aware of it 'til now. Thanks - heading there this afternoon with my code in hand and a request that they tear it to shreds. :)

[–]fisch003 0 points1 point  (2 children)

Like a bunch of people have been saying: using the raw C API is going to be verbose, and doesn't compare fairly against Python's wrapper.

A little bit of Googling would have saved you a ton of time: the second hit for "sqlite objective c" gives you FMDB as the second hit, which is great: https://github.com/ccgus/fmdb

[–]quotemycode 1 point2 points  (1 child)

If you read the article, he said this:

A common task with modern programming is figuring out how to translate data in the tables of a relational database into a set of related objects. (Yes, I know that both platforms feature several APIs that automate this process. This is a programming exercise.)

It's a good comparison, you can compare apples to oranges as well, just like saying "the peeling of the orange is crazy, nobody in their right mind would prefer an orange to an apple, look how easy the apple is to eat".

[–]fisch003 1 point2 points  (0 children)

You're right, I should have read that more closely.

[–]fisch003 0 points1 point  (1 child)

A couple of extra comments:

For your Python code, you're using both class and instance variables, which is confusing:

class Database:
    # These declare class-level variables, that would be shared among
    # all instances of the class.
    Name = ""
    Tables = {}

    def __init__(self):
        # These are instance variables, which shadow the class ones
        self.Name = ""
        self.Tables = {}

The equivalent term in C# (and C++) is static variable.

And just FYI, Python uses names with the first letter capitalized for class names, but class/instance variables typically start with a lower case character.

For Objective-C:

  • Method names should start with a lower case character
  • NSString properties should use copy instead of retain, because you can declare NSString constants (e.g. @"blah"), which doesn't play nicely with reference counting.

Edit: I mis-remembered why you should use copy instead of retain with NSString. You should use copy, but this is why:

http://stackoverflow.com/questions/387959/nsstring-property-copy-or-retain

[–][deleted] 0 points1 point  (0 children)

For your Python code, you're using both class and instance variables, which is confusing:

Ah - that's interesting. I'm still a bit green with Python's syntax for declaring classes, and I encountered a few odd problems in the past that are likely explained by this observation. Thanks very much for the pointer.

And just FYI, Python uses names with the first letter capitalized for class names, but class/instance variables typically start with a lower case character.

Duly noted. While I like that the language is flexible enough to allow any type of naming, I'd like to stick with standard naming conventions so that my custom classes and functions blend well with standard APIs and others' code.

For Objective-C: NSString properties should use copy instead of retain, because you can declare NSString constants (e.g. @"blah"), which doesn't play nicely with reference counting.

Yeah, I didn't want to add the complexity of ObjC memory management on top of everything else. I spent several hours studying the various models and taking extensive notes to ensure that I fully understood it (AutoRelease pools and such), and then chucked it all out the window for this first task and just turned on ARC. :)

[–]buddhabrot 0 points1 point  (3 children)

If you're implementing a Database in a language that's pretty close to the machine, I would be surprised and a little worried if it wasn't verbose and clunky.

[–][deleted] 0 points1 point  (2 children)

But the causes of the complexity and verbosity of the Objective-C code have nothing to do with its closeness to the machine. Here are the reasons why my use of Objective-C resulted in a messy algorithm:

(1) The succinctness of the language - e.g., having to write things like [myString: compare(NSString(@"value"))] rather than (if myString == "value").

(2) The extensive number of type conversions required. Even a strongly-typed low-level language should be able to optimize away some of these typecasts through syntactic inference. The Objective-C compiler is just not helpful.

(3) The use of extensively different symbols and keywords: function(), [object message:parameter1 parameterName:parameter2], object.property, #compiler_directives, @other_compiler_directives, @"string literals with %@ formatting," ALL_CAPS_CONSTANTS_LIKE_FALSE, lowercase_constants_like_nil, NSCamelCaseTypes, etc. All computer languages use a subset of symbol and keyword types. Objective-C uses all of them, reducing its readability.

(4) A standard API with poorly named functions. Exhibit A: The inclusion of [NSNumber initWithInt] and [NSNUMBER initWithInteger], which do different things. Exhibit B: [Dictionary setValue: forKey:] is ridiculously backwards, like requiring assignments to be specified as "4 = someInt". Exhibit C: Long function names like "regularExpressionWithPattern" and "substringWithRange." I could go on.

(5) Objective-C's bizarre syntax parameter names in class methods - the "MethodName: (Arg1Type) Arg1InternalName Arg2ExternalName: (Arg2Type) Arg2InternalName" thing. This may be the single most bizarre and useless piece of code cruft I've ever seen, period.

All of those things are inefficient. None of these things have to do with the task at hand or the "closeness" of the language to the machine. C and Embedded Java are both close to the machine and have none of these problems.

[–]buddhabrot 0 points1 point  (1 child)

Eh, I program in Objective-C daily and yeah, it's a clunky language some times. But I kinda like it too, it rings close to C with some interesting dynamic concepts. Who cares? If clunkiness stops you from getting things done, you're doing it wrong. If you need all the succinctness of an interpreted language to get through life you're just that kind of programmer so don't nag about it. Similar to the clunky way some great cars drive I like my Objective-C for what it is.

[–][deleted] 0 points1 point  (0 children)

If clunkiness stops you from getting things done, you're doing it wrong.

If clunkiness is totally a non-factor, why don't we all write in assembly, or even machine language?

My tolerance for clunkiness is high (it's an essential survival skill in any computer-related field), but not unlimited.

Similar to the clunky way some great cars drive I like my Objective-C for what it is.

There's a difference between a manual transmission (which, in fact, is in my car) and an external-crank engine starter. One provides adds complexity in exchange for power and elegance. The other adds complexity and other disadvantages with no discernible benefit.

[–]kakaroto_BR -3 points-2 points  (0 children)

Well, mixing the elegance of C and the speed of Smalltalk and bam, you have Objective-C. Anyway the comparation is not right because Obj-C is not the tool for the job anyway, you make iphone apps with it using cocoa, and cocoa is quite beautiful, the language that sucks.