Wednesday, August 26, 2015

Mobile accessories review

As some of you know, I'm a happy owner of Huawei Mediapad X1. So far it's the best 7" phablet (not counting the new Mediapad X2, obviously, which has better hardware with the same size and slightly changed buttons) but this post is not about device itself, instead I wanted to write a few words about cables, cases, screen protectors available on the market. By "market" I usually mean Aliexpress but some stuff might be available in your local stores as well. I'm not endorsing any sellers or brands, especially not original accessories, and prices are for reference only (and usually are for one piece and include shipping i.e. if you're thinking to buy a dozen of something, you might be able to find a better deal). In almost all the cases there might be cheaper options but with worse quality, seasonal deals and everything tend to change every month as new manufacturers and sellers come to market.

Unlike competitors' devices in the same form factor (I'm not pointing at Samsung right now), Mediapad X1 is small and narrow, it's not a tablet and it can be used in many ways people usually use smaller phones, but it still requires a large pocket or a bag to carry around. It would be interesting to write about cargo pants, vests, slings, funny packs, armpit bags, mini backpacks, etc., but I'm not doing it at least just yet. Suffice is to say that pants are my current favorite.

I somewhat dislike conventional Bluetooth headsets, haven't tried any wearables so far, and haven't decided yet whether or not I want to buy Talkband B2 (about $180, but just $150 in my local stores as of this week) so this part I will also skip. Cheap $1 earbuds is what I use (yeah, I also dislike in-ears).

First of all, regardless of what kind of case or cover you decide to use, screen protector is a must (no Gorilla Glass here). There are two kinds of protectors: protective film and tempered glass. Price is about $1 for the film and $4 for the glass. Given that tempered glass protects better and both are cheap, choice is obvious. It makes sense to buy a few extras in case you can't apply it first time or in case it breaks. In my local stores I managed to find a film for $2 (I needed it because the old one got scratches and I waited for the delivery). Universal films is also a thing, they will do if you need something urgently and nothing else is available, not recommended otherwise. Applying a glass is actually somewhat easier that applying a film with one major difference (with the protectors I saw, anyway): if you have a bubble and try to make it go away applying pressure, it can metastasize in form of micro-bubbles, they usually aren't visible but are a little bit annoying so make sure there's no dust (and buy extras).

Second of all, cases and covers. There are three major kinds of them: flip-case, flip-case with window, and back cover. As a sub-type of flip-case, there is a trifold case which can be used as a stand but from my experience this device is so not tabletish that you wouldn't want to do that very often. Of course, there are different materials, colors, manufacturers, prices, but that all is secondary and subjective, so shop around, try different ones.

Flip-case with window is obviously the most high-tech thing. Small window shows time, some notifications, and allows to use camera without opening the cover. No flashlight though. Beware of very cheap listings with no feedback: some of them are so cheap that window doesn't work. Starting from $3-4.

Usual flip-case is less attractive as it requires you to flip it every time you need to see the time or something. Not convenient at all for my liking. But, on the bright side, in this category there are wallet cases in which you can carry two credit cards or id and credit card (although maybe it's not the wisest idea to carry phone, id, and money in one place). $6.

And last but not least is the back cover. My recommendation is to always compliment it with tempered glass screen protector, never put it to bag with heavy objects, and switch to flip-case (or put into an additional case) when travelling because screen is very vulnerable. But other than that it's my current favorite: in all the flip cases device just feels too flimsy and bulky while it's actually very thin and narrow, it's also the best if you use camera or flashlight often, and usually being soft and elastic such cover can sometimes actually protect your device from falling better than the hard cases. Traction is better, I like the look, and port and button protection is effective. Buttons might be a bit tight hard to press and port protection (not present in all covers) is inconvenient for some. About $3.

Travel cases might be good to compliment back cover but I haven't tried any yet (I'm thinking Cocoon Travel Case 7 or similar). In the same category there are waterproof bags, sport cases, and then slings and funny packs (never used any of them).

Flip case with attached qwerty keyboard might be a thing (about $15) but I find them not very usable on the go (and I do most of the typing on mini laptop anyway) while at home you can use just any Bluetooth or USB keyboard.

Yes, the latter would require an OTG cable. There are two kinds of them: with and without external power ($1 and 50¢ respectively), there are also small adapters (20¢). Buy several of each, and then buy and extra one to carry in backpack and another one to leave at home. Much like a microUSB cable, this is the accessory you need often, for many devices, and will probably need even more often in future. If there are some devices (thumb drives, keyboards, etc.) that you use only with phone but not with computers, you can just plug it into an OTG cable (or adapter) and never unplug. Because those cables are cheap and you will need them regardless of your preferred device until USB-C become a thing which will not be until after a few years and then some.

Unlike some competitors (again not pointing at Samsung and Sony), Huawei still uses microSD cards as a main storage, and although you won't take the card out often, a small reader is still a good thing to carry on your key chain (50¢).

Stylus is a thing that almost nobody uses these days (maybe hand-writing could be good, not sure) but it's cheap enough if you need it (50¢).

Next time I have nothing to do I'll probably write about my experience with the phablet itself and maybe about my expectations from X2. Stay tuned.

Tuesday, August 25, 2015

Settling the bracket discussion once and for all

There are quite a few ways you can format a multi-line function call/list/dictionary in a programming language. With Python (at least with PEP8) it's just two ways: hanging indentation and vertical indentation. The latter is quite straight-forward and I mention it in the notes below. The former one is what this post is about. Well, about a minor but important question of where to place the closing bracket when using it.

Yes, style is much more than formatting the commas and brackets so let's settle this and move on to the more important questions.

When using hanging indentation, the only true way is this one(*):
some_tuple = (  # Nothing here, only opening bracket.
    item3, item4,  # Several items on one line is acceptable though not recommended.
    item5,  # Last comma is important. And never, never place the closing bracket here.
)  # Again, nothing here but the bracket and it's on the same level as the opening line.
Empty line after the opening comma is mandated by PEP8 even though there are a few cases where doing otherwise would've been a possible alternative, like:
class DoNotDoThis(object):

    def just_do_not(self,
and there is a reason for that — anything after the bracket makes the opening line less visible. That's part of the reason for the two spaces before inline comment rule.

The last comma(†) and separate line for the closing bracket is important because you don't really want to see another commit in git blame just because another item was added or deleted and you had to add a comma or move the bracket. You you're using Vim, it also makes adding/deleting easier because you can operate with the whole lines (it helps with just any editor but with Vim it's more so).

I'll repeat: closing bracket should be on separate line and on the same indentation level with the beginning of the opening line (if some_tuple is indented by four spaces, closing bracket should be indented by four spaces).

It might sound like a minor issue but 1) it's the only meaningful way of doing brackets once you think about it, and 2) they should be formatted in uniform way throughout the code so why not pick this one from the three or four PEP8-compatible alternatives(‡). It's one of the things that are easily controllable with pep8 linter (or flake8 which I actually prefer, the same thing but better) — you might wanna configure some auto-check in your editor/IDE, most of them allow that easily (plus, autoindent helps tremendously).

(*) The only case when you place the closing bracket on the line with the last item is this (so-called vertical indentation):
call_some_function(argument1, argument2,
                   argument3, argument4)
Although I'm not fan of this style, it's been around since Kernighan and Ritchie... But still, don't do that, especially with long arguments. Also, while it's still acceptable to put a closing comma on a separate line when using vertical indentation, it looks kinda ugly for me.

(†) There is one case where there should be no last comma. If it's a function call/def and you're using *args or **kwargs. It's almost not worth mentioning because you don't add stuff after **kwargs and it would just result in syntax error if you placed a comma there (not sure why it was implemented that way, but that's the way things are). But still a separate line for the bracket is preferred.

(‡) The text of PEP8 is little ambiguous on this point and some variations acceptable by the letter of it are not allowed by the recent versions of the linter, but it's essentially three options for hanging indentation: a) closing bracket on the separate line on the same level of indentation as the items (doesn't work well with if/while/def blocks), b) closing bracket on the same line as the last item (makes editing harder and messes with git blame when you add/remove items), c) what I have presented above. (There is also d) bracket on any other other level of indentation, like four spaces more than for the items, but that just makes zero sense.)