Friday, February 16, 2018

UX fail: Swagger

Why do popular applications have such glaring deficiencies in usability? Case in point: Swagger.

In this case, the "user" is the developer trying to implement Swagger or the OpenAPI spec.

Swagger is the messiah of API documentation, come to save us all from bad APIs and poor documentation and to relieve us of the tedium of writing boilerplate API code. It has it all; an editor and interactive tester that verifies your API, a code generator that will produce boilerplate code in dozens of languages and a really nice way to make beautiful documentation of your API available to people who want to use your API. But to get all this you have to learn the OpenAPI (formerly Swagger) specification. That's not the worst thing, especially if you're starting from scratch, and the editor and tester definitely improve the quality of your APIs. It's worth it to learn the OpenAPI spec since you get a lot of benefit for the effort.

Here is some documentation of OpenAPI and how to write it using Swagger tools. You can download the tools and use them but the easier way to do it is use SwaggerHub online. As long as you make your APIs public, you can create and save up to 5 APIs. If you want to develop and store more than 5 APIs in SwaggerHub or make them private or allow collaboration by a team, you will pay a minimum subscription fee of $75 a month (5 users) and the fee goes up as you add more team members. Here is a tutorial for SwaggerHub.

Great tools, but what about the massive library of APIs that already exist? How do you improve them and provide useful documentation? Well, painfully.

Swagger has libraries to add to your existing APIs to display documentation along with your API, if you annotate your existing code properly. Annotating is tedious and implementing the libraries isn't simple, straightforward, or easy to understand thanks to the fact that the documentation and examples aren't very good for this. This shouldn't be a surprise since most developer documentation isn't very good; most authors make huge assumptions about the understanding or capability of the reader and make magical leaps in their explanations that skip over a lot of important stuff that the reader may not know. But when Swagger claims to be trying to make documenting APIs better so they're easier for consumers to understand, they should also make their documentation here better so developers can understand and implement it more easily without having to go to StackOverflow.

Most people write APIs either by writing the tedious and repetitive code by hand or writing the output in JSON (or XML) and using some kind of code auto-generator to write the code, which drastically alleviates the tedium and amount of time spent writing code. Their are benefits and drawbacks to both approaches.

Writing the code by hand gives you much more control over the output, but if you have a large API it gets tedious. Writing the output and generating a schema from it is beneficial because you start from the final result and work backward so you can adjust the output until it looks the way you want, then you just run a utility to generate the code, saving a lot of coding time. The drawback is that you have to understand how to modify the schema to get the code to do what you want. If you're trying to produce both JSON and XML output, this can get really tricky because of the differences in the way certain things like arrays are represented.

Java XML bindings have had useful tools for years—for example, XJC or Apache CXF—to generate code to consume and produce both XML and JSON from an XML schema (essentially what a Swagger/OpenAPI does for JSON).

If you want to generate Java objects and code from JSON or a JSON schema using Jackson, Gson, or Moshi Java libraries, there's a helpful website for that.

The difficulty is building the XML schema in the first place but that has been made easier by several online tools that will generate schemas from sample XML. Converting from XML to JSON can be painful, but there are also online tools to do that. If you pick only one format—XML or JSON—the auto-generated code works great. If you want to provide both and allow the consumer to choose based on the HTTP request header (JSON or XML) you need finesse; in other words, it's not easy.

A great feature of Swagger CodeGen is its ability to generate code in over a dozen popular programming languages, not just Java. Swagger wants you to develop your APIs by first learning the OpenAPI spec then using the OpenAPI spec to generate the code. That's great, and OpenAPI is not too difficult to understand, but what do you do for existing APIs that you would like to improve by creating an OpenAPI doc?

Swagger finally released a tool, Swagger Inspector, to allow you to provide the results from an existing API and have it auto-generate the OpenAPI spec for you. Great idea! Except it doesn't work. Well, it does, but the results are almost useless. If you follow the brief video tutorial (another here) you will end up with an entirely different result. All it generates is the very simple description and endpoint; something you could have done yourself in a few minutes. Where the bulk of the work lies is in describing the object schema(s) in the result; the actual fields and value types (string, number, boolean, array, etc.). Swagger Inspector does none of that, even though it would be pretty easy to do. Hopefully this will show up soon, because Inspector is essentially useless right now. Good idea; not very well developed.

See also:

FasterXML Jackson Tutorials here and here
JSON annotations for FasterXML

Sunday, January 21, 2018

UX Fail: Slack

I wanted to add a link to a message in Slack that didn't have the full ugly URL. In other words, instead of:

https://www.mysite.org/my-blog/2017/10/this-is-the-thing-to-read?lang=eng

I wanted it to look like:

Here's my link

This is trivial in most email applications. Select the text, click on a tool that allows you to create a link for it and you're on your way.

But Slack isn't an email application, you say. Sure, but it's used for sending messages; sometimes fairly complex ones that we want to add some fairly simple formatting to so it doesn't look like a mess.

How to do this in Slack? So far I haven't figured it out. I know it's possible using the Slack API and Message Builder, but now I have to go learn the API and figure out how to use Message Builder, neither of which is documented in a way for mere mortals to understand. So now I have to invest hours of time to become an "expert" in an application just to do something that is fairly common and I expect (foolish me!) to do without much difficulty.

To do something even simpler like bolding or italicizing text, you have to learn Slack's cryptic markup language and put strange symbols in your text. Sure, there are hints underneath the message entry window for the symbols to use, but that's not a user experience most people are familiar with. We're looking for links or buttons above or below the editor. Markup is for people who enjoy wasting precious time memorizing every application's variation of markup and reading documentation to learn what it is.

Really, Slack? This is as good as your UX gets? Massive fail.

Try making stuff easy for people who don't want to spend an hour or a lot more having to become an expert in yet another stupid software application just so they can do something that's common and should be easy.

More Slack fails:

  • Can't delete messages when I make a mistake or regret sending something.
  • Pressing Enter automatically posts the message instead of just creating another paragraph which is what anyone who uses a keyboard to create a message, document, or email expects the Enter key to do.


Thursday, November 9, 2017

Photography: Aperture, Shutter Speed, ISO

There are three settings that affect how much light the camera sees: aperture, shutter speed and ISO. They have additional effects that will also be explained. This chart shows the essential effects of aperture, shutter speed and ISO.




Aperture

The aperture controls how much light your lens lets in. A lower number indicates more light. Each "stop" higher, for example from f/2.8 to f/4, reduces light by one half. Each stop lower doubles the light. The aperture is varied by an iris diaphragm located in the lens. Its behavior is analogous to the iris of your eye.


Aperture also affects focus range, also known as depth of field. This is the range between the nearest and farthest objects in a scene that remain in focus. A lower, brighter aperture has a shallow depth of field. A higher, darker aperture has more depth of field but also lets in much less light.


Depth of field is also affected by the focal length of the lens. A "longer lens" like a 200mm will have

Shutter speed

The shutter controls how long the shutter lets light in. A lower number is slower and allows more light to collect on the sensor. Each doubling of shutter speed reduces light by one half. There are several types of shutters. The common focal-plane shutter just in front of the image sensor has two "curtains" that follow each other rapidly to adjust how long the sensor is exposed to light. One opens to let light in and the other follows it to block light.


Shutter speed also affects how well you can "freeze" motion in a scene. An image taken at a slow shutter speed like 1/30 of a second will blur if the subject moves. A fast shutter speed like 1/500 of a second will freeze motion but allows less light and must be compensated by a wider aperture or higher ISO to let more light reach the sensor.


ISO

ISO is an indication of how sensitive the film or digital sensor is to light. A higher number is more sensitive to light and allows you to shoot in lower light and at faster shutter speeds or higher (darker) apertures. There is a tradeoff, however. High ISO results in pictures that look more grainy and have more color noise, especially in dark areas of the scene. This may be acceptable for small pictures, but the grain and color noise become more apparent as the picture size increases.

At small sizes the differences between a low ISO of 100 and a high ISO of 6400 aren't very apparent. Using a high ISO lets you capture pictures in low light that you wouldn't be able to with a low ISO.


At larger sizes, the grain and color noise are easy to see.


Exposure Triangle

Aperture, shutter speed and ISO interact and affect each other. The three-way interaction is often called the exposure triangle. To get a correctly exposed image in different light you have to balance the settings of all three. Shooting in auto mode takes care of this for you, but shooting in other manual modes gives you more creative control.


Equivalent Exposure

If you increase the shutter speed from 1/125 to 1/250, you let in half as much light. In order to get the same amount of light as at 1/125, you need to increase the aperture by one stop which doubles the amount of light let in.  Here is a table that shows equivalent exposures for different shutter speeds and apertures at the same ISO.

Shutter Speed Aperture
1/2000 f/1.4
1/1000 f/2
1/500 f/2.8
1/250 f/4
1/125 f/5.6
1/60 f/8
1/30 f/11
1/15 f/16
1/8 f/22

Assuming the ISO was set at 100 while using the above combination of shutter speeds and apertures, if you double the ISO to 200 (twice as sensitive to light) you have to either double the shutter speed (half the light) or decrease the aperture 1 stop (half the light) to achieve the same exposure.

For example, at ISO 100 and shutter speed 1/250 at f/4, if you double the ISO to 200, the equivalent exposure would be 1/500 at f/4 or 1/250 at f/5.6.

Here are a couple exposure calculators that let you play with settings to see the relationship.

Available light exposure calculator

Exposure calculator to compare two camera exposures

Helpful Resources and Tutorials


Basics of Photography: Your Camera's Manual Settings (lifehacker)

A Comprehensive Beginner's Guide to Aperture, Shutter Speed, and ISO (PetaPixel)

Shutter Speed Chart and Tips on How to Master It (BorrowLenses)

Basics of Photography: The Complete Guide (lifehacker)

Video Tutorials


Photography Tutorial: ISO, Aperture, Shutter Speed (YouTube)

Aperture, Shutter Speed, ISO, & Light Explained–Understanding Exposure & Camera Settings

Cheat Sheets

Digital Camera World publishes cheat sheets that have a wealth of information consolidated into one graphic that you can download or print. Here are some articles with useful cheat sheets in them.

How to understand f-stops

Which shutter speed should you be using?

How to understand ISO settings

Depth-of-field decisions


Thursday, January 14, 2016

Whassup Google Street View?

These guys in Gig Harbor, Washington spotted the Google Street View trike in September 2012 and decided to have a little fun. See for yourself:

Two guys fighting in the park


Navigate using the arrows (< and >) in the Google Street View link and see what happens.  The sequence starts about here as they spot the camera guy:

Check it out! It's the Google Street View guy!


I was telling a friend yesterday who was visiting Tacoma that he should take a quick trip to Gig Harbor while he's there.  It's only about 15 minutes from where he's staying.  I haven't been there in years so I thought I'd check the waterfront for parks or restaurants.  That's how I came across the Mixed Martial Arts guys in the park.

My curiosity was piqued and I read a little about Google Street View.  The Street View feature of Google Maps is a great way to orient yourself when you plan to go somewhere. You can get a feel for a neighborhood and spot interesting places to visit.

Google uses spherical cameras to capture numerous 360° panoramic images as a cameraman travels roads, byways, hiking trails and inside buildings.


They've mounted them on cars, trikes, backpacks, trolleys, even snowmobiles. Others have gotten into the action by submitting their own 360° images.  Here's more about Google's process for capturing and publishing Street View images.

Google Street View homepage and featured images

Google Street View camera fleet, publishing process, user submissions

The random candids captured on Street View have become an Internet phenomenon with several web sites documenting the unexpected scenes, like this one.

Street View Fun

The Gig Harbor Ultimate Fighters belong to a growing fraternity of pranksters mugging for Google's cameras.  CNN reported on a famous "murder" caught on camera in Scotland.

Murder on Google Street View?

All in good fun.