Monkey Business

By Peng Xie

Let the monkeys out!

monkey_business_by_d_mac

“Monkeys?” 

Of course we’re talking about monkey tests here… There are actually two types of monkeys — the smart monkeys and the dumb monkeys.

A smart monkey, knows the application it is testing, and follows a certain set of rules when it comes to doing its job. A dumb monkey, like its name suggests, knows pretty much nothing and behaves more randomly. One can think that a monkey in real life is probably somewhere between our smart monkey and dumb monkey.

There are advantages and disadvantages for both types of monkeys. A smart monkey, while being more effective to find bugs, does require more effort to “train”. The developer needs to create the said knowledges and rules for the smart monkey before it can start the tests. A dumb monkey is more likely to find random, out-of-the-box bugs. But thanks to its unpredictability, the bugs found by a dumb monkey may be harder to reproduce. Some would even question the value of monkey tests since it may take a long time before they can find any bugs.

“But why?” 

I think monkeys are important friends of developers. Here’s a story:

Xuanzang finished his app. He used test-driven development procedures and wrote all the unit tests for all components of his app, including “comprehensive” UI tests. (At least that was what he thought.) His app passed all tests with flying colors. He were happy and released it to the public. A day later, weird UI related crash reports started to show up in his inbox. People had given his app negative reviews. And he were no longer happy.

“Why? The app passed all tests!” exclaimed Xuanzang.

His monkey friend came and touched a part of the UI that “a normal user would not think of touching.”

The app crashed.

The monkey friend relaunched the app and long pressed a button that “a normal user would just tap.”

The app crashed again.

You see, the monkey is not a “normal user.” As developers, it’s easy (and absolutely normal) to assume a certain user behavior when making test cases. Because we designed the app to function in a set boundaries, we may be blind to some behaviors outside of the box. A wise man once told me, when it comes to test cases, if you think you are already crazy enough, the real life will always out-crazy you. To save our sanity (and time), we need to ask our monkey friends for help.

“Where can we make friends with the monkeys then?” 

A lot of places actually. Not in the zoos though…

If you are an Android developer, your monkey friends are actually living right in your Android Studio! They run on your emulator or devices to produce random streams of user events.

For iOS developers, Apple has yet to introduce us any monkey friends. But we do have SwiftMonkey that lives in GitHub. It even has a framework called SwiftMokeyPaws to let you see where your monkey friends have touched in real time in your app’s UI.

Those are only a few examples. If you search, you can always find a monkey friend with a very particular set of skills…

Advertisements

Ethical Dilemmas of Technology: Privacy

By Xinye Ji

170328103911-internet-privacy-780x439
“Arguing that you don’t care about the right to privacy because you have nothing to hide is no different than saying you don’t care about free speech because you have nothing to say.”

-Edward Snowden

It’s difficult to overstate how much privacy we give up to have access to services such as Facebook, Twitter, Instagram, Google, or even Amazon. With every click, whim, or action, we tell the services we interact with a little about ourselves bit by bit. As time goes on a clearer profile of each person is created, and interesting conclusions can be drawn from these profiles.

The movie Yes Man satirizes the worst case scenario when Carl, Jim Carrey’s character, is arrested on charges of potential terrorism due taking flying lessons, studying Korean, approving a loan to a fertilizer company, meeting an Iranian woman, and buying plane tickets at the last minute. While the situation was comically exaggerated, the film brings up an interesting social commentary of the state of our privacy. We run the risk of pushing ourselves further into a surveillance state.

Speculatively, one could argue that applying this data aggregation comes from a place of good will. In fact, terrorism prevention is a frequent argument that the US government makes to continue the activities of the NSA. Aside from crime prevention, there are many different applications to utilize aggregate data. For example, aggregated data now informs us about real-time traffic. Our aggregated profiles can tell us about possible car repair. Are these conveniences worth giving away your information? What about if Target could tell you if you were possibly pregnant based off of your purchases? Or what if Facebook could tell if someone was about to commit suicide? Or what if Microsoft could tell you that you have pancreatic cancer a month before you knew it yourself? Are these advancements in technology worth the loss of our privacy?

This blog post might seem a bit eclectic and contrarian to itself. I don’t intend to draw any conclusions of this topic as we could go on forever about it. However, I do believe this ethical dilemma is something that we, as a society, have to decide on in the near future. For the time being, however, I hope that the average citizen considers and understand how to protect one’s liberties in the digital age.

WWDC 17: Why am I excited as a developer?

By Peng Xie
wwdc17-og

WWDC 17: Why am I excited as a developer?

It’s been a week since WWDC and I finally got time to write this blog post to express my excitement as an iOS developer. I won’t be talking about the keynote, since it’s pretty much the same every year. Instead, I’ll be focusing on the real deal, WWDC 2017 Platforms State of the Union.

For the non-iOS-developer readers, Platforms State of the Union is a session in WWDC that gives attendees a more technical overview of what’s coming to Apple’s platforms, as its name suggests. Just like previous years, Apple made some really big announcements to its developer community. Let’s see some of my personal favorites.

Xcode 9 Source Editor

As an iOS developer, I use Xcode everyday, which sometimes can be a pain. Xcode’s performance and features are not that strong comparing to some of the competitors. This year, Apple introduced one of the most welcoming changes to Xcode in my opinion – they have re-written the whole source editor from ground up in Swift! The result? 3x faster file opening seed, 60fps scrolling and up to 50x faster jump-to-line action. On top of that, they also implemented an integrated markdown editor, improved coding issue presentation and tokenized editing. What’s even better? A brand new refactoring engine and workflow that is powered by an open-source transformation engine. IntelliJ users may not be that impressed with these improvements. But to me, the all new source editor will give me a huge boost in productivity. I can’t wait for it to come out of beta… (Rule of thumb, don’t use beta Apple softwares on production development works.)

Swift 4

Not surprisingly Swift 4 will be there with Xcode 9. Apple has vastly improved one of the most widely used classes in Swift, String class. In Swift 4, String is now a range-replaceable bi-directional connection, meaning it behaves and can be used like an array of characters now without any sort of conversions. Thanks to the underlying improvements, String now provides 2.5x-3.5x faster processing depend on the language it’s in. Another welcoming news is the introduction of “codable” type. The new type will be synthesized by compiler and has the ability to perform 100% type-safe JSON encode/decode with only one line of code. Apple also made it easier to adopt Swift 4 in Xcode 9. The compiler now supports both Swift 3.2 and 4.0 and allows developer to mix-and-match 3.2 and 4.0 targets. All these improvements makes Xcode 40% faster building large mix-and-match Swift/Objective-C projects. Moreover, building projects using multiple Whole Module Optimization targets is now 2x faster!

iOS 11

One of the biggest announcements in WWDC 17 is iOS 11. For users, iOS 11 blurs the line between a desktop and a mobile OS, which will finally make iPad Pro a viable productivity tool. For developers, this means new APIs to play with. Starting with the new Drag-and-Drop feature, Apple did a phenomenal job making it easier to integrate in apps. It’s automatic for text and web content, and has delegate protocols for customization similar to other iOS APIs. With its cross-process, system-wide multi-touch support and built-in data security, I’m sure developers will start to provide this new feature in their apps to users as soon as iOS 11 becomes available.

Good news for everyone

Along with Xcode 9, Swift 4 and iOS 11, Apple also introduced CoreML for machine learning, Metal2 graphic engine and ARKit for virtual reality. These are only a few that caught my eyes. I am really excited to learn more about CoreML and hopefully can put it to use in one of our apps someday. I truly think Apple has given us developers really good tools and platforms to provide users best features and experiences. This is good news to developers as well as users. A better Apple will surely push its competitors to step up their game, which is something I really like to see. Whether or not you’re a developer or iOS/macOS user, you should be excited too. As consumers, we will always benefit from the competitions.

Properties and KVO

By Peng Xie

The other day I came across a bug when I tried to use Key-Value Observing to observe the change of a property in some not-so-modern Objective-C class. The observer was never notified when the property’s value changed. It took me a long time to figure out what was wrong and I just want to share my findings, so you don’t have to be upset should you ever run into a similar situation.

It all started with a simple “@synthesize” statement.

Some background first. In “Adopting Modern Objective-C” document, Apple recommends using properties instead of instance variables (or iVars) in “as many places as possible”. One of the benefits listed is “Auto-synthesized getters and setters”. If you still remember all the “@synthesize” statements in stone-age of Objective-C, I believe you will just love auto-synthesizing feature in modern Objective-C as much as I do. (Almost) No more “@synthesize”! Isn’t that sweet?

Even though synthesizing is no longer required (most of the cases, and usually not even recommended), you can still use it to synthesize a property with a backing iVar (Compiler will create an iVar with the same name of the property if there isn’t one created by developer.) and custom setter and getter. However, if you don’t make your setter KVO-compliant or just simply ignore setter and change backing iVar’s value directly, KVO will obviously fail to observe the change in property’s value.

A well-designed custom setter or a setter created by auto-synthesizing calls “willChangeValueForKey:” and “didChangeValueForKey:” methods at appropriate moments to send observer notifications so that observers that implements KVO methods know when a property is changed. If new value is directly assigned to a backing iVar, the setter is never called and hence there will be no notification sent for KVO. Not only will your own KVO code not work, any framework you may have used in your project that depends on KVO will also not work.

You can find a demo project here. In the demo, if a property’s value is modified without using the accessor (setter in this case), KVO won’t be able to observe the change.

TL;DR Listen to Apple and use properties wherever possible.

Opposite View: WWDC15 Keynote from a Developer’s Perspective

By Peng Xie

OS X El Capitan

  • Oh the new name, good luck translating it into other languages…
  • Pinned Sites in Safari: It’s gonna be useful when browsing Facebook, Twitter, etc. at work, class… Apple’s engineers really understand what we want after all.
  • Enhanced Spotlight: I actually didn’t know you couldn’t check weather and search things with your own words with Spotlight in Yosemite.
  • Mail App: I’m gonna write emails to all the people I know with all the tabs I can have in new Mail app’s compose window and still ignore emails from Phil Schiller because I can search for all emails I ignored from Phil!
  • Spilt View and Window Management: Seems like Apple learned something from Windows 7?
  • Metal for Mac: RIP Open GL… While the PC gamers are playing GTA5 with awesome graphic, Mac gamers are still stuck with games like vegetables vs zombies. Let’s see if these big game companies can convince PC gamers to buy Macs.
  • Have I mentioned that El Capitan is faster than Yosemite?

iOS 9 and WatchOS 2

  • Siri now has a new animated interface. I wonder what will you see if you look at it with red-blue 3D glasses…
  • Siri can also do way more than it (she?) could before based on its (her?) soundings.
    • “🎵It sees you when you’re sleeping… It knows when you’re awake…🎵”
  • Like in OS X, Spotlight on iOS has received a new interface and can now look into your apps for search results.
  • Apple Pay now works at more places than ever! And apparently Apple and Google seem to have reached some agreement to switch the names of their payment app. Yes, I’m looking at you, Android Pay and Apple Wallet.
  • Happy drawing in the new Notes app!
  • Maps app can now tell us which bus/train to take to go to places!
  • Apple now lets you choose what news you wanna read in its new News app, as long as you’re in US, Australia or UK.
  • People have been asking for an “iPad Pro” for some time now. Apple’s answer to it is a new QuickType keyboard with shortcuts plus touchpad capability and a more powerful multitasking feature (Samsung, get your lawyers ready!).
  • You’ll be able to use the awesome Picture in Picture and Split View feature if you have the latest iPad Air 2.
  • Swift 2 will be open source later this year, available for iOS, OS X and Linux. I feel sorry for Windows because it won’t get all the wonderful new features comes with Swift 2.
  • It seems like WatchOS 2 can finally do what it suppose to do a long time ago. Apple has finally given access to normal frameworks and features like animation & layout for Apple Watch.

Everything about Music

  • For $9.99 a month, you get another Spotify alternative. That’s it.
  • And the crazy developers at Apple are developing an Apple Music app for Android as well!

Overall impression
I am not happy about this keynote and it’s not because there’s no new Apple TV or other new toys. WWDC is a developer conference and it should focus on new operating systems and SDKs, not music. Unlike previous years’ WWDC, Apple rushed through announcements and demos and spent what seems like forever for their new music streaming service. I understand it’s important business for Apple but they really should have spent more time talking about WatchOS 2 and Swift 2.

Not Impressed

Not Impressed

 

How to learn iOS Development (Part 3)

By Peng Xie

[You can read previous parts of this series here: Part 1  Part 2]

It’s been a long time since the second part of this series was posted. Hopefully my experience on note taking is helpful. In this final part of the blog post, let’s talk about how a developer can evolve from “just being a developer.”

Sky’s the limit

It’s common sense to keep learning for professions like developer. I’m at no position to tell someone what he/she should learn but I think there really shouldn’t be any limit on what a developer can learn. Making an app from scratch involves efforts from different aspects such as design, project management and so on… For instance, basic image editing skills are easy to pick up and will make things way easier when you want to make some small changes to an image you want to use in the app. And knowledge on project management can help you better plan and estimate your development work. In my opinion, having those knowledges and skills can be extremely useful for any developer works independently or in a team. After all, you don’t always have a graphic designer or a project manager in your team.

Always something new

iOS (or Cocoa in general) developer community has been active for a long time and there’re tons of awesome things that satisfy all kinds of needs for developers. For example, ReactiveCocoa framework provides additional APIs for functional reactive programming using Objective-C. And tools like Reveal makes tasks such as debugging user interfaces much easier and efficient. The geeky side of me always like to spend free time to discover and play with new frameworks and tools. It’s an interesting way to learn about new coding styles and enhance your own apps from those open source frameworks. I usually visit Ray Wenderlich’s tutorial website, NSHipster and objc.io to learn about new frameworks and tools. Websites like CocoaControls are also good places to discover UI related frameworks.

One for all, all for one

We benefit a lot from other developers with all their fantastic works on different frameworks and tools. As members of the developer community, we should give back to the community and help other developers whenever we can. Contributing to open source projects and answering questions on websites like Stack Overflow are good ways to learn from other people. We can learn about types of issues other people encountered and discuss different approaches on fixing all kinds of issues. Moreover, having a good profile on GitHub and Stack Overflow also makes you stands out from other people when you try to find a new job.

Where to go from here?

It’s actually never possible “just being a developer.” Sometimes you have to be a graphic designer or a project manager. And if you want to, you can also be an adventurer, a contributor or a tutor. Let us know in comment section what you think about this series and what other topic you want to see in the future.

Keep learning and happy coding!