Friday, September 1, 2017

The Mobile Startup: Episode 5: Some thoughts about tech, and work.

Knowing that You're Bad!

I think that if you have never thought of yourself as a bad engineer before, then you are probably a Bad engineer!

Diverse Experiences in Tech as a programmer

Over my 10 last jobs, over the course of 14 years, no two of them were even remotely similar. The amount of variation in terms of field, company size, culture, personalities, skill sets, and process is really high. I think it made me a lot stronger in general. Nothing like going through a few rounds of lay-offs to understand why certain things happen in business.

The Unique Feeling of Visceral Mastery

Experiencing extreme effortless mastery in person doesn't compare to reading about it or watching an internet video. It can really change you forever.

PARTNERING UP: Always beneficial

I found that partnering up brings a lot of value, serving as a constant critical feedback loop and a cross-benefit relationship. If you can't get a real person, use a rubber duck. Its the "Dummy Developer" concept which can also bring you value by pulling value out of yourself. Just dont get caught talking to it out loud about systems design... 😂

THEORY OFF / ON: being Naive on demand!

This bit is about being able to be naive on demand for 30 minutes, and then being theoretical again for 30 minutes. The reason? Promote action and feedback ahead of over-analysis, for the sake of balance and speed. Let me know your thoughts in the comments below.

DEVELOPER TOOLBOX: Building generic components.

The reason humanity has reached such great levels of scientific advancement is because each person who contributes, does so based on years of proven discoveries made by people before them. So as a developer I'm trying to keep this in mind. In order to keep getting more productive, I want to build on top of previous discoveries that are tried and tested. Those can be others' or my own.

Tuesday, May 30, 2017

The Mobile Startup: Episode 4 - Obsessed about social media and vlogging


So much new information

I got obsessed about Social Media Marketing, ever since discovering Gary Vaynerchuk and his YouTube shows: Ask Gary Vee and DailyVee.  I bought and read his latest books:  Jab Jab Jab, Right Hook, and "Ask Gary Vee", and I am completely convinced that a social media presence is no longer optional.  "Every company is a media company now" - Gary Vee.  

Basically, there has been a platform shift, where millions of people are now on TV creating content.  And If you are not creating content, then you are out of the game. 

So here we go.  I will just talk about exactly what's on my mind.  And I feel I have a lot to share with the world, based on my experiences with business so far, and after 12 years in the Tech field as an engineer. 





Sunday, April 30, 2017

The Mobile Startup: Episode 3 - New Relaxation App into an extremely overcrowded space.

I have just released "Relax Utopia": A new iOS app for relaxation, yoga and meditation, featuring scenic photography, music and nature sounds. There are no ads and no purchases.  You can get the app here: https://itunes.apple.com/us/app/relax-utopia-sleepy-sound-gallery/id1223240574?mt=8

The plan is:  to get as many users as possible, and get at the core essence of solving a very common consumer problem.   I also believe that while every other competitor is nickel-and-diming everyone on in-app purchases, I can figure out a better way to monetize the whole thing much later on in the cycle.  This app is going to remain free for a long time.  
Most importantly: this app is made on a reusable, generic platform, which can be used to quickly make similar apps in the future.  Currently, the bottleneck is by far marketing and distribution. 

I will mainly be looking for ways to customize it to what the majority of people want most.   Enjoy!





From the iTunes description:
This app is the ultimate nature relaxation experience for the iPad or iPhone. A Lush, Seamless flow of gorgeous landscapes and chill sounds to fill your senses. Everything happens automatically. Just lay back, relax, doze off, or simply leave this on your table, to get lost in Utopia. Use this for your yoga workout or meditation, relax after work, as you are going to sleep, or as an animated picture frame.

FREE for a limited time. Get it while you can. 
No Annoying Ads!
No Purchases! 

Please tell your friends, and tell me what you think about the app: RelaxUtopiaApp@gmail.com

Features:
- Brightness slider allows you to reduce brightness and the blue color in images, to help you sleep easier. 
- Over 30 relaxing, high quality sounds. 
- Over 300 nature images faded into one seamless slideshow. 
- 5 classical piano masterpieces by Frederic Chopin. 
- Save any image to your library.
- Share any image to Facebook.
- Auto mode - scrolls the image slideshow slowly. Images fade into each other in one continuous flow. 
- Animation mode - animates each individual image separately
- All Sounds Mode - Plays 2 random sound effects at a time until cancelled. 
- Collapse and fade out all buttons, so only the nature remains. 
- Control music volume separately from sound effects. 
- Landscape or Portrait modes. 

Saturday, April 29, 2017

Creativity, Noise, and Learning how to Learn

Creativity in Business

I think that right now, creativity is the number one trait to have in business. Of course: hard work and hard skills are always going to be important. But creativity is what's gonna allow you to
cut through the noise. And right now, noise is most abundant. And people think of creativity as: painting, art, music, and it is, but it's also pronounced in less obvious ways, such as: thinking of
problems in ways that are not ordinary or not intuitive.

Learning how to Learn and what to search for


Just by elimination, there should always be the best way to buy something, or to do something, or to advertise, etc.  So how do you go about finding the right way to do something?  I think that knowing what to search for has become a very important skill.  And also, defining a process on how you learn. Information has become commoditized. It's free. Wikipedia has something like 4.5 billion pages on it. And skills are getting cheaper too. Because there's sites like ELance, where the competition is very still. So, the more unknowns you can deal with, the higher you would be paid.

The Importance of Social media



I recently started dwelling on how important social media has really become lately.
In the last 5 to 7 years, we got all these new companies: social networks, they are distilling their own versions, their own recipies for how ideas are shared and attention is held. And it's a gradual transition on each of these versions, and because it's gradual, although constant, it can catch you off-guard, like it caught me off-guard.

I've been in the industry since 2005. I've had 10 different technology jobs. But I somehow got blindsighted, and probably my focus was not on it, but I did not stay on top of all the social media. People also have a tendency to maybe stereotype social networks, just like any other medium: just skepticism, like "somebody posting pictures
of their cat. That's all it is". But no: it's a very serious thing. Social media is pretty much the basis of all communication going froward, and that's not going to change.

Essentially there`s been a platform shift. So we got all these people on TV now, because
the phone is the TV. And because of that, that's effectively 100,000 times more
people on TV than before. So the attention of people is the most prized
resource that there is. And because of that, we are seeing things
like Snapchat cutting length down to 10. Twitter cutting length down to 140. And things getting deleted automatically. It's because we are being saturated with noise. So this is gonna be a fun ride. I'm very curious to see where we go next.

Cheers!

Taking Social Media Seriously


The term "Social Media" could be stereotyped by some as "Posting pictures of your cat on Facebook".  But it's so much more than that.  

- Fact: Your business now has a 1 degree of separation from the most influential people in the world.  So the way I see it, if you can make a huge impression and engineer the engagement, then you're in the door.

- Social Media is not just entertainment.  It's the basis of all communication as we know it.  And it's constantly evolving.

- Attention has become the most valued resource, because there are now hundreds of millions of people who can rapidly produce high quality content.  The content to attention ratio is skewing exponentially, further compounded by previously accumulated content.  The amount of web pages (including all forms of media) has got to be in the hundreds of trillions by now (if you include every page that historically got traffic, on every popular website).

- People are improving with their techniques on all social networks.  Therefore, those will always get saturated, and new ones will emerge.

- Because of the point above, i predict that the Long Tail content model is going to suffer from continuous dilution going forward.   The Hot Trend content model will be superior, but is obviously more competitive than ever before, as everyone is jumping on the bandwagon.

- Social media is the best way to get attention: on your brand, on yourself, on your message.   This is because everybody has a phone in their pocket that is tied to every social network effortlessly.  You can now produce videos right on your phone, then throw them onto 10 platforms, all in half an hour.  If your video is truly special, you will reach millions of people.

- We are seeing multiple versions emerge of how communication between people and businesses should work.  And we are just getting started.

- Social media is changing people's habits and lifestyles.  It's disrupting consumer behavior in ways that are hard to analyze.  This is because, each person is a unique snowflake, and the number of use cases is extremely high, to be able to analyze reliably.

Monday, April 10, 2017

The Mobile Startup: Episode 2 - Strategy

The Purpose of Strategy

Let’s discuss business strategy and how it applies to a startup with very little capital. 

I feel that defining a strategy for what I'm doing, and how, makes it easier to keep going in my new startup, because it gives me comfort and a set of boundaries to stay within.  I am currently still working full time, so time is very precious, and eliminating unnecessary scope seems very beneficial, so that I am only focused on the core functionality. 

There are so many unknowns when you’re starting something new.  You will always have more questions than answers.  You may want to do everything at once, and have huge plans, but you’re limited by time and manpower.  This is especially true when you have a full time job.  You really have to learn to be comfortable with uncertainty, and at the same time be ready to invest 2 years or more of hard work, before seeing any kind of traction. 

Since I work a 40 hour work week, i have chosen a highly opinionated strategy where a lot of things are eliminated right off the bat, so they will not distract me from the core of what I want to create and achieve. 

"Doing a startup is like building an airplane while attempting to take off, and at the same time decide where you want to fly to".   - Unknown

"Running a business is like eating glass while standing at the edge of a cliff".  - Elon Musk

My Specific Strategy

My chosen strategy partly involves the following 10 points:

1. Making very simple apps (one page only, or only one optimized, targeted task).  This eliminates any critical mass-based social ideas that require a lot of users to be viable.  So we are talking about simple tools (at least on the surface), or apps that provide simple entertainment or utility.  

2. A strict time limit of a maximum of 80 hours per project, with a preferred of 40 hours.  If the project is exceeding this time frame, that means, we need to cut some features.  The rationale for this is, in completing the project sooner and releasing it, we will gain insights about the market, and prevent unnecessary effort, focusing our ongoing effort in the correct direction. 

3. The Agile manifesto is something I want to strongly abide by.  As many changes as needed to get results, as late in the process as needed.  Collaboration over process.  Working, production quality software at all times. 

4. Continuously building on top of previous code, coming up with a Library of code that can be used for the future. 

5. Single purpose apps that must do 1 thing extremely well.  Any additional features, would take second priority to getting the key feature right. 

6. Focusing on all my strengths.  I wanted to do something that puts me in the strongest position possible, where I can utilize all of my previous experience and skills for the most part, only gradually learning new things.  I want to be utilizing my strengths 80% of the time, and learning new tech the remaining 20%.     Ask yourself:  "Does Michael Jordan mow his own lawn?" - he's probably highly capable of doing so, but it's not the best use of his time.   I will also only get involved in areas where I have interest in.  Otherwise i wouldn’t enjoy it. 

7. Have at-least one differentiator.  Although i like Long-tail ideas as well, I prefer that every idea has at-least a single differentiating factor that makes it special and unique, even if that differentiator is a limitation.  (Example: Twitter and the 140 character limit.  Snapchat, and the inability to view previous snaps.  These are not the only limitations that define these products, but they're part of it. ). 

8. Periodic zoom-out to re-assess your direction, with at least one other person.  Sometimes I need to pause what I'm doing and reflect on all the things that I have.  I would rank these things, and put together a list of the strongest five.  Then I'd figure out how to use them together.   For me these were (from stronger to weaker): 1. A well versed technology background as well as prior experience implementing new ideas from scratch. 2. Music knowledge and experience (theory and performance).   3. Strong desire to succeed in the tech field in order to have multiple streams of revenue from the global market.  4. Appreciation for great software design, quality, efficiency and code re-use.    5. Numerous hobbies and interests, which can be used as a springboard for many different apps. 

9. A heavy focus on marketing, benchmarking against the top names in the competition.  Seeking out cheap forms of marketing which are not mainstream yet, and thus undervalued and cheap to buy. 

10. The MVP-first approach (Minimal Viable Product).  The first version is always considered a proof of concept, and not a final production grade system.  Which corners to cut is determined on a case by case basis.  I can not, for example, just make a blanket statement that "None of my apps would have a server side component, and be completely only Client Side".  That would be too restrictive.  Most likely, the deadline for each project would dictate the corners which would be cut, combined with the pragmatic assessment of the remaining product's benefits with those corners having been cut. 

What I learned from some of my previous part time projects

- JamCat: Lack of focus on the key feature can result in your app not being adopted, and having poor retention rates.  Adding too many features which are not thought through properly results in users never coming back, because they are not getting the benefit out of your tool. 

- Transpose: Even a simple text only app can be useful to people, as long as it solves a real problem.  I myself had a problem that I needed solved when I played in a band.  That was:  to be able to move entire chord progressions with notes in them, with only 1 press.   So definitely other people had this problem too.   This project was a good validation for my line of reasoning at the time.  That is:  You don’t need award winning UI to create real value for people. 

- Meow Pix: Relaxing Cat Slideshow with Music. The "Relaxation App" is an extremely saturated market.  So far, after 1 week after go-live, the organic traffic from the App store has been non-existant. People are simply not finding the app by it's name and keywords.  I consider the marketing material in the app store to be strong enough, and now focus needs to be put on promotions and creative advertising approaches (preferably free). 

All 3 projects require significantly more marketing effort and further in-depth analysis to fully understand, and I'm definitely not there yet on all of them.

Next products on the roadmap

- Nature Landscapes.  (Another relaxation app focused on nature and sound effects. A seamless, lush experience where the user just dozes off, and nothing is needed on their part.  This can also be used as an animated picture frame)

- Guitar Chord method.  (I am not impressed with all the Guitar Chord resoures on the app store.  I can make something much cheaper, and much more useful in an 80 hour iteration.  This is next on the list, and it will be exciting). 

- Toddler interactive "Flash Cards".  (Since I have a 2.5 year old who I can use to test my app on, I want to apply any existing tech I have to the Toddler learning use case, after having watched my son play many games, I can see what it is that kids of his age are looking for). 

- Scientific calculators, formulas for various use cases. 

- Product Information in multiple business areas.  This is a long-tail business model. 

These are only some of the areas I'll be getting into.  I hope to have released a total of 10 apps by the end of this year. 

Stay tuned for the next episode where we will get into the more technical details of building an app from scratch, and my general approaches to software development. 




Tuesday, April 4, 2017

The Mobile Startup: Episode 1 - Intro & My Mission

Intro

I'm starting a new blog series that I intend to continue for a few years, where I will describe my whole experience building a technology startup from scratch.  I am a software developer now running my own, brand new company with a lot of ideas for apps and projects which I am now developing one at a time. 

- A very casual series where we will discuss: business strategy, picking your battles, marketing, software development practices, implementation of ideas, project management and other fascinating insights about the market.  
- We will focus on the mobile field, marketing and other tech opportunities.  
- We will start with creating simple iOS applications from scratch, and documenting our progress with periodic updates. 
- Anyone can ask me questions and learn from my mistakes, as the operation grows.  
- You could also give me hints, if I get stuck, if you want to share your own experience. 

About Myself

- My skills include: programming, project management, leading small teams, playing jazz guitar/piano, video/audio production, recording and singing.
- I am a 34 year old software developer from the Toronto area.  
- I went to college in Toronto for Computer Science taking taking 9 semesters in total, including a 2-semester co-op term.  
- Graduated in 2005, and since then I have had 10 full time programming jobs without taking any breaks in between, other than vacations.   
- The last 3 gigs have all been contract, since I started consulting.  
- I've been involved in many practices:  client, server, mobile, databases, operations support, software design, implementation, outsourcing, leading small teams, but mainly programming. 
- I have settled into specializing in iOS architecture, because I enjoy the Xcode environment and like the iPhone and the apple ecosystem.  
- I am however interested in pursuing the following areas: content creation, social media marketing, big data and statistical analysis, web 2.0, android, wearables, IoT, VR, Blockchain and other future cutting edge tech.  

Key Intentions: 

- Keep projects as simple as possible
- Focus on best practice, clear UI design
- Clear definition of features and problems
- Targeting the mass global market.  
- Accelerating the rate of development, by building a set of generic automation tools and a shared codebase that can be reused.  
- I am new to social media marketing, but I will be be documenting the process of learning and practicing marketing from the perspective of a software professional. 

Starting Portfolio

JamCat App   - band activity, song list, and set list manager.  Website and iOS app that organizes bands and everything they know how to play.   This took me a few years to build. I'd say there are over 1000 hours invested in this app part time since 2012. 

Song Transpose - An app that helps you move chord progressions up and down, ignoring everything else contained in a song profile.  This was a 3 week project.  It made 70 sales so far, without any promotion effort whatsoever.  

Meow Pix - a Relaxation app containing images of cats, classical music, sound effects, and other features.  This only took 3 weeks to build.   A 45 hour effort. 

- These apps are just the starting point, used as a learning platform for marketing. 
- I will keep open to building ideas in sectors other than mobile, however, the scope is to be kept minimal, to fit an MVP format. 

In the next episode I will describe my current strategy and brand new set of projects that I'm working on, as well as others that are in the pipeline.   Also look forward to an occasional vlog on my YouTube channel:  http://youtube.com/FranticRock

Cheers,
Alex






Saturday, November 19, 2016

My take on software quality, common pitfalls, and the mindset for success.

Common Pitfalls

This article applies to all branches of software development, and is my view on software quality, based on 12 years of experience as a software engineer.  We will be looking at common pitfalls, and how they can be addressed by a particular line of thought or strategy. 
What makes software projects have poor quality and grind to a halt, or have costly production defects?  Based on industry feedback, some of the following symptoms are causes of software failure: 
  1. Insufficient attention to detail and care for the code.  (Patch on patch, fixing only immediate symptom, without understanding root cause). 
  2. Lack of proper object-oriented architecture (resulting in ever increasing complexity of code). 
  3. Copy and Pasted code (violation of DRY)
  4. Improper design (violation of SOLID)
  5. Poor coding practices (huge methods, too many conditional statements or "accidental complexity")
  6. Separation of concerns missing. (Grouping many duties into one method, class, object, event or variable. ). 
  7. Unclear definition of concern separation. (Not sure what is the single responsibility of each class, method, variable, object, etc) 
  8. Unclear / ambiguous naming of variables / objects.  Names not specific enough, resulting in need for comments. 
  9. Fear of refactoring.  Fear of making changes.   (Afraid because we are not sure what is broken after making a change). 
  10. Lack of or complete absence of unit tests, resulting in no way to cheaply have assurance of correct behaviour upon making changes. 
  11. Inability to "Step Back" and ask really difficult and uncomfortable questions.  (Should we even be doing this?  What's the benefit?)  - Tunnel Vision. 
  12. Lack of "Ownership" of the code.  Afraid to change.  Unwilling to figure out how it works.
  13. I'll remember to do it later.  It's fine for now. 
  14. I really want to learn this new thing, so i'll use it, even though it's doesn't quite fit. 
  15. Accidental complexity allowed to continue unchecked. We keep adding features without thinking about design and making the code easy to re-use and grow. 
  16. The "Not enough code" syndrome.  Now we all know that "less code is better", mainly for maintenance reasons.  But actually, a lot of the time, you need to have a lot of code in order to fully address the requirement, and do a good job implementing the feature you envisioned.  Things are often simple on the surface, but you need to have a great UX and cover all the edge cases.  So you might need to write a lot of code.  Just make sure to architect it in a way that makes it all separated by responsibility.  Don't compromise on that.  Ask yourself: "Does this software suck because we didn't fully flesh out how it should work?" 

Strategy for Success

So how do we not only avoid the above grim situation, but on the contrary: achieve the complete opposite?  We reverse each point above into its' positive counterpart: 
  1. Meticulous attention to detail in every line of code we write. (We should be proud and confident about our code.  We can easily speak about the decisions we made and their justifications. Not:  "it sorta works, i guess". ). 
  2. Think through the design of every feature first.  Even if its' a minor feature.  Examples:
    1. Do i put this in the view controller?
    2. Is this likely going to be reused later by someone?
    3. Can it be made completely generic?  What's the extra effort in doing so? 
    4. Does adding this increase the complexity of the class where we are adding this? (and thus it's $$$ maintainability)
    5. By adding my code, did i just make the object do more than 1 task?
  3. Is this task already done somewhere else?  Is it in multiple places?   Can i take it out of those various places and instead put it in one place, and reuse that?   
    1. Doing this for every feature you implement continuously improves the overall strength of the code base. 
    2. Notify other developers of these reusable resources:  building up your team's "Toolbox".    ("Hey, i made this category which makes sure things are done on the main thread, with one line of code!") 
  4. Refer to wikipedia, on SOLID definition.  (https://en.wikipedia.org/wiki/SOLID_(object-oriented_design))
    1. In Pull requests, the reviewer, can asses each of SOLID's properties, to check for violations.  Fix at PR stage. 
  5. Enforce the following guidelines:
    1. Methods can only be 20 lines of code or less. 
    2. Classes must be 700 lines of code or less.  (If exceeding this, start making component classes out of your class with Roll-Up objects, that can just be used with a few lines of code - Facade pattern). 
    3. Nesting (If, switch, loops, blocks), not more than 2 levels deep.  (3 levels deep or more = you must break it up into separate methods). 
    4. Single responsibility for every object.  Few exceptions are:  Facade class which manages other objects, but know little to nothing about how they work internally. 
    5. Rely on abstractions in areas which are likely to change.  (In other words: if something is likely to change, put an interface around it, with a simplified entry point to the functionality).  I believe abstracting everything is a waste of time though.  So the judgement call is:  What is most likely to change? 
  6. What is the primary responsibility of this class (every class)?  The answer should be provided in one short sentence, always. 
  7. We should first define what the different "Concerns" are, and then consciously place classes into those buckets.  
    1. For example, responsibility can be separated into into: 
      1. Networking
      2. Navigation
      3. Persistence
      4. Generic Views/Controls
      5. Business Specific Views/Controls (can reuse Generic Views internally) 
      6. View Controllers (screens comprised of components) 
      7. Components.  (More complex than just a view or control.  It's a business-specific UX piece that does a single job). 
      8. Utilities.  (Many categories here.  These are always generic and reusable.  Do not know about business rules, that are likely to change). 
      9. Configuration
      10. Styling (Style sheet)
      11. Localization
      12. Accessibility
      13. Analytics
      14. Validation
      15. Alert / Dialog utilities
      16. Resource / media access  (really easy way to access images from network or local)
  8. "Take that comment and make it a method".  
    1. Then put the code into that method.  
    2. Voila = self-documenting code. 
    3. It's OK to have long method names (within reason).  
    4. If the name is too long, then is it doing more than one thing??
  9. The more you do refactoring as you implant features, the easier it will become.  Just like any skill - it's acquired over time.  I believe refactoring should be constant, as development continues. 
  10. Let's say you have 600 unit tests.  You can run them overnight on all OS versions, example: iOS 8.0, .1, .2, .3, iOS 9.0, .1, .2, .3. iOS 10, etc...   You will uncover edge cases on specific iOS versions using these tests.  You would have to have an entire QA department, and QA manager distributing work for them, to do this manually.  The cost would be 100 times or 1000 times more. 
    1. There definitely is a trade-off overhead in managing the tests, and setting up the CI for the first time.  But the act of managing the tests does give you extra insight into the state of the code.  (Reality check - what did i just break?, or how can the architecture be improved?). 
  11. The best code is No-Code  (guaranteed bug-free!!).  If you can avoid implementing something, just make the decision not to, and justify it objectively.  Some business requirements go away by themselves.  This is because assumptions get dispelled, and stakeholder input causes initial claims to be invalidated, making some requirements obsolete.  Example:  Your customer later tells you: "We actually can't have this feature because it violates privacy regulation number N".   
  12. "I just have to implement this one feature", i will just do it.   I can first check whether it's done similarly somewhere else.  I can ask another developer about it first.  Maybe someone in the department already delved into a similar task.  I shouldn't be afraid of making larger changes than what I planned.  Refactoring can improve the maintainability of the code. 
  13. Fact: The cost to fix bugs grows exponentially the later they are detected.  Example:
    1. Cost to fix in dev: $10
    2. Cost to fix in QA: $100
    3. Cost to fix in UAT: $1000
    4. Cost to fix in production $10000 or more.

      It's also better to leave the code in the best state possible, so other developers don't have the cost overhead of asking about what's going on.
  14. Using tech just because you want to put it on your resume is selfish, because you can just implement it simpler using standard tools, but using SOLID.  "A new co-op student should be able to figure it out".  
  15. Keep making easy to use facades in the code, abstracting away complexity.  Keep refactoring the code until it fits into the following set of guidelines: 
    1. Methods can not be longer than 20 lines of code. 
    2. Classes can not be longer than 700 lines of code. 
    3. Nesting of If statements, loops or scope levels can not be more than 2 levels deep. 
  16. Perhaps the implementation could be improved.  Sometimes this includes a lot of effort, R&D, or sheer brute force coding, but as long as the code is structured properly, it's OK to have a lot of code.  (Just think of a piece of software like MS Office, and how much code it has).  
Learn how to create your own Programming Language here!!

Monday, March 7, 2016

What does Playing an Instrument and Computer Programming have in common


I am a guitar player and a computer programmer.

I enjoy designing and coding software, as well as improvising on the guitar, particularly in the jazz, rock and fusion styles.  I've been thinking a bit about how music and programming actually have a lot in common. These 10 things are just the aspects that jump out at me, and may not necessarily work for you.

  1. Math at the Core: Computer programming uses math concepts to improve efficiency of code, such as when you're looking for an algorithm that executes in less time for your particular scenario, uses less memory, or CPU cycles.   Music theory uses basic arithmetic to define intervals between notes, that correspond to various tension levels you want to express.  Math in this case is used as a form of self expression.  Even if you are not aware of what a certain set of notes is expressed in mathematically, that math relationship is always there in anything that you play or listen to.  Same applies to software, which always winds up as ones and zeroes at the finest level.  

  2. Patterns and a Taxonomy to learn: Computer programming has logical patterns to organize and categorize the concepts you know:  classes, interfaces, design patterns, variables, enums, structs, methods, wrappers, adapters, pointers, variables, messages, delegates, weak references, data formats, algorithms.  Music theory uses chords, scales, triads, arpeggios, chord progressions / regressions, tonal centers, modal playing, shape thinking, contours, rhythmic variations, dynamics, phrase repetition, call and response, tension, release, mixture of voices, rhythmic displacement, harmonics, and feel to achieve the desired effect.  Both sides utilize these structural tools, each serving a distinct, specific purpose.  They are all, however, just a means to an end.  Being familiar with as many as possible of these is definitely beneficial for both trades.

  3. A Problem, and Solution: Computer programming has problems and unknowns. There are many ways to solve a problem, and an infinite combination of steps to get there.   Music has a chord progression that you may need to fill or arrange.  Or you could be trying to fulfill an idea which is just a melody in your head.  How you fulfill it, is completely up to you.  In both trades you often end up solving a problem that nobody cares about, but you have learned something in the process.

  4. A Scale of Clear Right/Wrong to completely Subjective.  Computer programming has common "right" and "wrong" ways of doing things.  Some choices are considered wrong, such as gluing SQL strings together, containing user input.  Music has some things that are very "wrong" too, such as playing a Flat 9 over a major chord repeatedly....  But Captain Beefheart would disagree.  Analysis is needed to  understand why a solution is considered "correct" and also that a musical passage is "tasteful" or of "high quality".  These conclusions are based on your personal line of reasoning, preconceptions, and requirements depending on your situation. Finally there is a Scale: A clear right and wrong on one end, and highly subjective decisions on the other.  We all decide differently where to put any given topic on that scale, although many common schools of though exist.

  5. Varying standards for Purity and Aesthetic. In Computer programming there is a certain aesthetic to your code. This includes: how clean and efficient it is, and how prone it is to breaking in the future. In music, you can also distill a melody or arrangement to its most essential parts, and subtract redundant pieces, until you're left with something that's "just right".  Some people are much more strict with this aesthetic than others.  How "cleanly" various roles are performed by different software elements can be correlated to how "cleanly" instrument tracks in a piece of music do their job.

  6. Knowing limits, breaking rules and common conventions. In computer programming, you may choose to break rules on purpose.  For example, you might DE-normalize a database table, building very specific indexes, so that very specific Select statements are quick to run, because you do not have to do any joins or contend with processes.  In music, especially jazz, you break rules all the time in order to create tension.  In more popular styles, you keep changing the well known rendition to keep things interesting for yourself - the musician, as well as the listener. This often involves infusing diverse influences into the rendition. 

  7. Exponential growth in variety. Computer programming has a proliferation of technologies which seem to be exponentially multiplying with the help of the internet.   The number of songs created, new music styles and cultural musical expressions is also exponentially growing.  The challenge for both is keeping up with the trends, and choosing what to even keep up with.

  8. Human Interaction is at the core. Computer programming has people you need to work with.  Some of them are very opinionated, overbearing or overly defensive.  The music industry has very similar types of people that you often have to work with.  Both trades, in my opinion, are as much about people skills as they are about the craft.  This human element applies at every stage:  From designers to customers.  From players to listeners. 
  9. Design determines what you can do.  How you design a piece of software often dictates what your limitations, possibilities and outcomes are in the future.  This applies to music, when you have a rough idea of the style of song you want to compose, the chord progression and the rhythm you have chosen.  It is generally uncommon to have a bunch of completely different, disjointed music styles, rhythms and chord progressions follow one another in the same song.  The "design" of the song must follow some specific train of though, so it can be understood.   The same applies to Software.
     
  10. Conventions, Rebellions and Inspiration. Every time traditional thinking is successfully challenged, we all enjoy the breakthrough.  Whether it's a hugely successful commercial success or a very niche following, we all love it when things are done differently on purpose.  If I can wire up 20 raspberry pies to uniquely control my house, or learn about Pat Martino's unique approach to using Minor Scales, I would be excited and inspired by the innovation factor, and the future possibilities.


Learn how to create your own Programming Language here!!

Beer in the Fridge at work

It makes me really happy to join a technology company and find beer in the fridge, people playing ping pong, sleep in sleeping pods, frying up BBQ at lunch, and playing basketball.  Not because these things are inherently fun.  But because, it's a message from management that says the following:

1. We hire such a high caliber of employee, that they would never consider abusing the perks we've given them.

2. Congratulations on finally getting to the top 10% of the best places to work.

3. People here are smart on many levels, not just book smart. They realize the value of maintaining a flexible mind and body.

4. We are all like minded in our pursuit of excellence.  We are so productive that we have plenty of time left over to enjoy the perks, after succeeding at our jobs. 

5. The company is successful financially, and would stop at nothing to satisfy and retain its employees.

This of course results in people giving back more, and feeding this cycle.

Wednesday, December 30, 2015

Writing Energy Efficient iOS Code



How to extend the user's battery life and improve user experience.

This transcript is from Apple's WWDC14 2-part video: "Writing Energy Efficient Code"

Overview

OSX 10 Maverix and UP, 2 new sections were added:
1. "Apps Using Significant Energy" in the battery indicator on the status bar.
2. "Battery Usage" tab in Settings showing by-app breakdown of battery usage.


Everything on the system uses Energy. Components include:
1. CPU (using a small amount of CPU makes a big difference to energy consumption)
2. Flash storage. (big dynamic range)
3. Networking.
4. Graphics. (A small change by the developer might cause an expensive operation under the hood)


There are 3 states of energy use:
1. Idle power (device is not being used.  apps not running)
2. System Active (your app is running code)
3. Intermediate States. (system is idle, but not able to get back to idle power.  Time is required to achieve this state.)
a. Device stays in this state a lot, if sporadic work is done.
b. This is the concept of "Fixed Cost".  Anytime sporadic work needs to be done, a minimal cost is incurred.
c. Fixed cost tasks (sporadic tasks) consume a lot of energy for the amount of work they actually perform. (high overhead)
d. The solution is: Bundle all the sporadic tasks together in order to reduce the fixed cost of your work.


Energy and Power are 2 different things.
Power is the peak value at a given, instantaneous point in time (measured in Watts)
Energy is the sustained combined energy usage to accomplish a task (measured in Joules)+

Better Performance most times means: Better Energy use

For small workloads, Fixed Cost will dominate
For intensive workloads, dynamic cost will dominate

POWER can be TRADED for ENERGY, for example:  a single threaded workload can be multi threaded in order to minimize the Fixed Cost. (The Dynamic Cost will stay the same)



Techniques:

1. Do It Never  (Avoid unnecessary work)

If another app comes in front of your app, are you still running animation code in your app?
If another view comes on top of the active view, are you still animating the parent view?
Use:
- (void)applicatioNDidResignActive
- (void)applicationDidBecomeActive
or listen for UIApplicationWillResignActiveNotification

Pause Timers and animations when resigned active.


2. Do It a a Better Time

If you expect an expensive operation such as downloading a huge update or content.  Schedule the work when the user is plugged in to a power source.
OS10 Yosemite has NSBackgroundActivityScheduler schedule things like:
- Periodic content fetch
- Update install
- Garbage collection and data maintenance tasks
- Automatic saves or backups

OSX:
1. Create an NSBackgroundActivityScheduler object with a reverse-dns Unique Identifier.  Re-use these identifiers for the same activity.
2. Set the tolerance  (in seconds.  600 = 10 minute from now start)
3. Set the interval (Execute every interval.  Tolerance applies on top of this)
4. Set reapeats = YES (if you want it to repeat)
5. shouldDefer (allows deferring work until the best time)
Interval will execute it once each Period (not at the same time each time).

Call activity scheduleWithBlock:...

NSURLSession Backround Session:
ou pass a bunch of NSURLRequests to the background session, and they will get executed Out-Of-Process on a System Daemon.
Delegate callbacks work as usual with NSURLSession
If your app gets terminated, your tasks will still be executed by the OS, and when App is re-opened, you will
retrieve your existing session by it's unique string ID, and you will get delegate callbacks also.

iOS7 and Up, you can set configuration.discretionary = YES;   (System picks the best time to do the work)
This provides bandwidth monitoring and automatic retry. (if bandwidth drops below minimum speed, task is paused and retried later. Handles edge cases for you)



3. Do It More Efficiently

iOS8 and up, has "Quality of Service Classes"
1. User Interactive (main thread interactions) - Is this work actively involved in updating the UI? Animations, input event processing...
2. User Initiated (Immediate results) - Is the user waiting on this content before next Interaction can be done.
a. Is it OK for Usre Interactive work to happen before my work?
b. Is it okay for this work to complete with other User Initiated work?
c. Is it oka for my work to take precedence over Utility work?
3. Utility (Long-running tasks) - Is the user aware of the progress of this work. Does it show a progress bar?
4. Background (Not user visible)

(This is a hierarchical priority)
The system prioritizes higher level tasks over lower level tasks..


Practical Example: Imagine we have a Grid View app with image thumbnails being imported and loaded:
1. User Interactive would be the Scrolling only (main thread)
2. User Initiated would be the Thumbnail Generation, and Image loading when clicked.
3. Utility would be Image import and conversion (progress bar shown)
4. Background would include search indexing.



Powermetrics tool can be used to see which QoS are in use. 
usage:  sudo powermetrics —show-process-cos —samplers tasks

Gives the MS per sec usage breakdown of each QoS class for your application. 

To see which QoS class is used while debugging: 
  • Pause in debugger. 
  • Go to the CPU tab to see breakdown of threads. 
  • You will see all the different threads and resource usage of each. 
  • For each thread it also shows the QoS class under the thread name. 

Spindump tool can be used to see which QoS is used to execute particular code. 
usage: sudo spindump -timeline MyApplication

Gives you the history of which QoS was used over the lifetime of the execution of your code. 

When the user is not actively interacting with your application, you want to aim to have 90% of all work to be at Utility or Below.  


4. Do it less:

CPU:  
1% CPU usage causes 10% higher use over idle
10% CPU usage causes 2x power draw over idle
100% CPU usage causes 10x power draw over idle. 

  • CPU use has a huge dynamic range in power.
  • Minitor CPU use with Xcode debug gauge
  • Intruments’ Time Profiler is the best tool to use for monitoring CPU usage. Gives a stack trace breakdown by CPU usage. 
  • Performance Unit Tests can be used to detect Performance/Energy regressions.  

Minimize Timer Use in the application:  to minimize the Fixed cost overhead associated with them.
Timer types:
  • NSTimer
  • CFRunLoopTimer
  • pthread_cod_timedwait()
  • sleep()
  • GCD timers
  • select()
  • CVDisplayLink
  • dispatch_semaphore_wait()

Use the # Wakes tab in the Energy Impact tab to find out how many times the app awoke due to a timer firing on average per second. 

sudo timerfires -p MyApplication -s -g 
Helps see all timer firings inside the app. 

Timer Coalescing:  Groups timer executions together, according to a maximum tolerance you specify.  Examples:
[myTimer setTolerance: 60.0];

CFRunLoopTimerSetTolerance(myTimer, 60.0);

dispatch_source_set_timer(my_timer, DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC, 60 * NSEC_PER_SEC);

This grouping of timer executions improves the fist cost of energy consumption. 
  • Be mindful of wakeup overhead
  • Monitor for wakeups
  • Debug with timefires
  • Specify timer tolerance
Graphics:
  • Avoid extraneous screen updates
  • Unnecessary drawing kicks graphics hardware out of low-power modes
  • Drawing more content than needed causes extra power draw to update the screen
  • Use needsToDrawRect: or getRectsBeingDrawn:count: methods to fine-tune drawing

In Debug options you can enable: “Flash updated regions” to visually see which regions are being updated, to check whether all those updates are necessary. 

If you apply a translucency or blur effect on an element that has other elements behind them that frequently update, this is an expensive graphical operation.  Better to ensure that frequently updated content is not behind any elements that have transparency effects.  (Avoid Blurs on updated content)


Storage:
  • Writes to flash are much more energy hungry than reads
  • Write the minimum content necessary
  • Aggregate the writes for better efficiency. 
  • Any I/O will pull device out of low-power states. 
  • Use caching to your advantage. 


Writing Energy Efficient Code Part 2


Recap: 

The Fixed cost of any resource is due to the fact that the resource stays powered on for a while after performing work, in case its’ needed for more work in a short period of time.  If no work is performed, then the resource is powered back down after a while.   

Trading Power for Energy is generally a concept of Using higher power in a shorter amount of time in order to minimize the Fixed cost of the work performed.  (thus reducing the total energy used) - “Do as much work as you can quicker, minimizing the overall energy used”. 

  • Do it never
    • Stop unnecessary work on app transitions
  • Do it at a better time
    • Scheduling with NSBackgroundActivityScheduler / NSURLSession
  • Do it more efficiently
    • Set appropriate QoS work priority
  • Do it less
    • Coalesce your timers

CPU Monitor:
Throws an exception if over-normal type of CPU usage is observed.
Example:
Exception Type: EXC_RESOURCE
Exception Subtype: CPU_FATAL
Exception Message: (Limit 80%) Observed 89% over 60 seconds. 
Catches “Runaway background usage"
But this won’t catch normal use which is happening in background, in times that it should not be.   

Energy efficient Animations:
Review your Blur usage and reduce frame changes behind blurs. 
Avoid extraneous screen updates. 



Energy Efficient Networking

  • Lots of small calls has the Fixed cost of keeping the radios ON over a period of time  (Overhead costs).   In this case, the overhead cost is very high in proportion to the amount of packets sent. 
  • Not all means of network transfer are the same.  For example: 3G web browsing for example is more expensive than WiFi. 
Conditions affecting network battery use:
  • Celliar vs WiFi 
  • Signal conditions
  • Network throughput

Solution 1:
  • Buffer data together and send as batch.   (Coalesce transactions)

Do it less/never 
  • Reduce media quality
  • Compress data
Avoid redundant transfers
  • Cache data
  • Resumable transactions  (or chunked transfers
Handle errors:
  • Timeout
  • Retry policies
Consider tolerance (doing it at a better time)
  • Understand the requirements - when really is it needed?
  • Consider technology used
  • Check network conditions before sending. 
  • Check data before sending it to make sure something actually changed. 
NSURLSession allows:
  • Pause/Resume
  • Caching with (NSURLCaching)
  • Background Sessions - out of process transactions
NSURLSession Example:
NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: @“com.apple.App.UserRestore”];
[config setAllowsCellularAccess:NO];   // Will only use WiFi - save the user money
[config setDiscretionary: YES];   // Take care of the task at any time within the window
config.timeoutIntervalForResource = 18 * 60 * 60;  // Within the last 18 hours. 
…  Now make the session and task with this config as normal.  

Summary: 
  • Coalesce your transactions
  • Coalesce your transfers
  • Consider tolerance
Measuring Impact:
  • Developer menu on the device now has an Instruments option where you can start recording an energy trace.
  • Then “Import data from device” to load this file .
  • Apps can also force display brightness to maximum. Make sure this is only done when absolutely necessary. 
Sleep:
“To sleep is to prepare for the longer journey ahead”. 
“The longer you allow your devices to sleep, the better the battery life”. 

Background best practices:
Notifications:
Device does wake up in order to send the local notification or push notifications. 
  • With Push Notifications, you can set the push priority.  (10 is default - immediately. 5 - Delivered at a power conservative time). 

VoIP

Previous to iOS 8 was Periodic keep-alive packets causing device wakes, and code complexity. 
As of iOS8 the PushKit framework now allows using the Push Notification service to talk to VoIP apps:
  • No persistent connection required. 
  • app relaunched if terminated
  • include up to 4k payload  (much more than the 256 bytes with regular pushes)
  • app runtime to process the pushes. 

VoIP Push example:
#import <PushKit/PushKit.h>

- (void) voipRegistration {
PKPushRegistry *voipRegistry = [PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject: PKPushTypeVoip]; // register

}

NOTE: VoIP Background mode needs to be requested for this to work. 

Delegate methods:
  1. Handling push tokens
- (void) pushRegistry:(PKPushRegistry*)registry didUpdatePushCredentials:(PKPushCredentials*)credentials forType:(NSString*)type
{
    // Register push token with server. 
    // There will be a separate token between VoIP and Push notifications. 
}

- (void) pushRegistry:(PKPushRegistry*)registry didReceiveIncomingPushWithPayload:(PKPushPayload*)payload forType:(NSString*)type
{
    // Received push
}

On the server:
  1. Request the VoIP push certificate on the apple portal
  2. iOS8+ only.  

Location Optimizations:
  • Example: Location based restaurant suggestions. 
  • [locationManager startUpdatingLocation] will keep your device ON continuously. 
  • Accuracy affects energy use. (more precise is more energy used)
  • Only use this when necessary, and turn off continuous updates when not needed. 
  • Make sure to Turn OFF location Updates when not needed. 

If you don’t need GPS level accuracy: 
  • locationManager allowDeferredLocationUpdatesUntilTravelled:timeout: 
(Only notifies if you moved a certain distance)  500 meters or 5 minutes for example. 
Example: Weather app. 

Region Monitoring:
  • When entering or exiting a specific location.  
  • Set up a specific region you care about.  App is only woken up when condition is satisfied. 

Significant Locations Visited API

BLE

Peripheral-side buffering can be used to only wake the device when the peripheral’s buffer is full. 
Can also group unrelated transfers into one wakeup occurrence, such as a BLE transfer at the same time that Location entry is satisfied.
Learn how to create your own Programming Language here!!

The Mobile Startup: Episode 5: Some thoughts about tech, and work.

Knowing that You're Bad! I think that if you have never thought of yourself as a bad engineer before, then you are probably a Bad e...