HNHacker News
TopNewBestAskShowJobs

zserge

587 karma · joined April 13, 2012

Hey, I'm Serge. Born in Ukraine, living in Munich, MSc in Software Engineering, brought up with a love for simple things, now doing all sorts of software development, mainly Go, C/C++, JavaScript and Python.

https://zserge.com

submissionscomments
zserge··on Kotlin for Android Developers
Just made a big push to Anvil repository - it can now inflate layout from XMLs! This means you may use your favourite IDE to design layouts, then use Anvil to bind data and event listeners to make your UI reactive:

    public override fun view() {
      // A designer gave us an XML with some fancy layout:
      // a viewgroup with a button and a progress bar in it
      xml(R.layout.my_layout) {
        backgroudnColor(Settings.bgColor) // will modify root layout view color
        
        withId(R.id.my_button) {
          // button state may depend on some variable
          enabled(isMyButtonEnabled)
          // button click listener can be attached
          onClick { v ->
            ...
          }
        }

        withId(R.id.my_progress_bar) {
          visible(isMyProgressBarShown)
          progress(someProgressValue)
        }
      }
    }
I know many people are opposed to defining layouts in code, so this can be a good compromise for them. Also, it's very helpful if you have a large project made with XMLs and want to refactor it.
zserge··on Kotlin for Android Developers
Kotlin is a very nice language especially from the Android developer perspective. It's so concise that you may not even use an IDE having only a text editor instead.

In addition to Anko, there is also a similar (but much smaller) library that I maintain - https://github.com/zserge/anvil

It is also a DSL for defining view layouts in code, much like Annko. The major difference is that Anvil supports data binding and has reactive nature (think of it as of react.js for android).

zserge··on LIL: The Little Interpreted Language
I like the language and we actually have been using it in production a couple of years ago. It was really easy to write extensions (like plain old C functions). Later we've moved to Lua because of the performance and because the code in LIL quickly became unreadable.

But the language is really nice, very similar to TCL. I wish it got more attention.

zserge··on The Kotlin Language: 1.0 Beta Is Here
Build times are used to be slower, but I think recent Kotlin compilers have "daemon" mode to speed things up.

I personally use Kotlin on a daily basis for Android development and build time is comparable to the one of Java. May I also recommend Anvil framework (https://github.com/zserge/anvil)? It brings declarative layouts and data bindings, which works best with the immutable data types of Kotlin (much like React does in the web).

zserge··on A modern way to build reactive Android user interfaces
Here's a couple of posts about why Anvil has been recently rewritten and how it works now:

- http://zserge.com/blog/anvil-breaking-changes.html

- http://zserge.com/blog/anvil-forge-merged.html

Now it's more focused, more stable, and much faster.

zserge··on Few.swift – React-Inspired Library for Writing AppKit/UIKit UIs
If one is looking for something similar for Android - you might like Anvil: https://github.com/zserge/anvil
zserge··on Clipboard.js: Modern Copy to Clipboard
Glad to see new libraries for the new clipboard API! I was recently making a color picker website that would not use flash for copying color values (http://0xrgb.com) and I was really missing a library like this. Anyway thanks, I hope it will replace zeroclipboard very soon!
zserge··on Why I'm turning JavaScript off by default
When I was making my color picker (0xrgb.com) - I did it with NoScript in mind as well. I agree that whenever it's possible the websites should deliver content without javascript or flash.

However the web now seems to be both - web sites and web apps. If you run a blog or a news online magazine - it's still a good old web site. It would be nice to have semantic markup and not depend on javascript that much.

But if you're writing a web app - that's becoming tricky. Semantic markup becomes a burden, since all you naturally want is a hierarchy of nested divs/flexboxes with styles (as in any other GUI framework where you have views and layouts, and not text-related "articles", "links", "ordered lists", "headlines", etc).

I always had a feeling that web apps is something out of this nature - they try to adopt cumbersome markup language, unsuitable layout engine and slowish programming language to create modern interactive GUIs. And I think since it is all too unnatural - we have this endless race of changing frontend frameworks, languages and technologies seeking for a better way to achieve the goal despire of these broken HTML/CSS/JS. There's been some progress, for sure, but it still feels like writing AI in assembler or UNIX command-line tools in C#.

zserge··on Flash-Free Clipboard for the Web
Might be fixed now. Can anyone confirm please?
zserge··on Flash-Free Clipboard for the Web
Sorry, I don't have a Mac here to test, could you please file an issue here: https://github.com/zserge/palette (yes, 0xrgb.com is open source).

By "fails" - you mean it doesn't select/highlight the color string, nor it does copy it to clipboard?

zserge··on Flash-Free Clipboard for the Web
I was so disappointed that every color picker website nowadays uses flash/zeroclipboard to only copy HEX color value (6 letters!). It's so slow and inefficient. I ended up making my own one using this clipboard API - http://0xrgb.com

Glad to see that FF now supports this API, too!

zserge··on A Scheme Interpreter for ARM Microcontrollers
Great project! I think Espruino is in the same niche. However Espruino looks much more "user-friendly" - it has tutorials, it explains how to build an interpreter for certain developer boards, it has lots of hardware-specific modules with documented APIs and it has a shiny IDE for newbies.

Scheme could have it all, it even fits better, since it's a smaller language and presumable a faster one. However this project looks abandoned. Also, and interpreter written in assembler would be oh so hard to debug I think.

Do you know if there are other projects with alternative languages for STM MCUs except for eLua and Espruino?

zserge··on Es: a shell with higher-order functions
Thanks for the link! I like how the sources look (much cleaner than the original plan9 rc), I like the way the addons work with this rc implementation and in general the project makes good impression. Sad that it doesn't have many stars on github, and doesn't have a nice readme yet (I see it is about to be added in the developer branch).

I find doubtful the support of multiple readline-like libraries (and no linenoise though) though. I would rather prefer to have one, but fully supported (with custom completion etc like in zsh). I still need to check how this feature could be added.

zserge··on Es: a shell with higher-order functions
I find rc shell to be much more logical than a normal sh, but nowadays it's only used by a few people, so for the new users there is little sense of learning it - most people haven't even heard of rc!

I think that are two ways to change this situation:

1) For normal CLI users - let's pick the most up-to-date implementation (tobold's rc, es, inferno's sh, suckless' rc...) or write one from scratch if that would be easier. Then think about writing plugins for git, for colorful prompts, for autocomplete, for common development tasks etc. Since rc language is easier and cleaner than bash - writing plugins and extensions for it should be easier. Of course, many blog posts must be written showing how superior it can be comparing to bash in some cases and how easier it is to learn. Once the resulting rc gets into every linux distro and mac and there will be known repositories like ohmyzsh - people may start switching from bash to rc, not from bash to zsh.

2) For embedded systems - from my experience sh scripting is normally done not for the desktop, but for tiny embedded systems, where busybox is a definite winner - maybe an alternative can be made by using rc shell and Plan 9 set of utilities? So we get a single static binary (again, rewrite rc in Go?) and a small set of tools, that might even work on windows. I think it could be smaller, like toybox, but with a usable shell interpreter.

Since most implementations of rc are now unmaintained (correct if I'm wrong) - probably it would be better to rerite it in some modern language (Go, Rust, maybe C++), cover with tests and start promoting it. If so - I would be happy to join the development (I started it once, ended up with just yacc-generated AST parser, but I though it might become a huge project that nobody is interested in, so I suspended the development).

zserge··on Is ReactJS really fast?
Mithril is awesome (been using it for 7 months now). I really like that they finally have implemented components and described how they should be made.
zserge··on Kotlin M12 is out
Big programming languages are built from big JARs (compiler, runtime, stdlib). Loading those each time in memory is a long process. Using nailgun saves ~10 seconds on my laptop.

Another problem is compiler performance (both Kotlin and Scala compilers compile less statements per second than Javac), but it's not that dramatic.

Finally, dexing languages with runtime (kotlin - ~200KB, scala - more than 1MB) takes time.

Luckily, Buck optimizes most of it.

zserge··on Kotlin M12 is out
Kotlin is a really good language. I really want it to be my primary language for android development. The only problem I have now is build times. It's about twice as slow to build a Kotlin app than Java app.
zserge··on Kotlin M12 is out
I'm now trying to use Buck build system with Kotlin. It looks like in the M12 kotlin-compiler.jar the annotation NotNull.class is embedded twice.
zserge··on Android M Developer Preview and Tools
Right, the runtime speed of Kotlin is very good. But the build times got much slower. An average java build with Gradle takes ~30 seconds on my pretty old laptop, but with Kotlin it is about 1 minute. Daemon and parallel are enabled in global gradle properties. I think running Kotlin compiler as a daemon would help, but I don't see an easy way to do that with Gradle.
zserge··on Android M Developer Preview and Tools
Do you use Kotlin with Gradle? I like Kotlin a lot, but it feels very slow on my laptop, do you know if there any special optimizations to make it faster?
zserge··on Android M Developer Preview and Tools
Oh, finally I'm not alone here! I use vim/tmux and yesterday I discovered Buck and made a quick project generator: http://zserge.com/blog/buck-build-system.html
zserge··on Buck: A high-performance build tool for Android
Finally my android builds are fast enough to not lose the focus waiting for the build to finish! Thank you, guys. I wonder if Buck supports Kotlin, or if not - how hard would it be to add it?
zserge··on Anko – Pleasant Android development in Kotlin
My first candidate for removal would be fragments. They don't help to componentize apps at all (at least not better than plain old viewgroups), but they can make life much harder with weird hidden bugs.

There is brilliant article from Squareup about that - https://corner.squareup.com/2014/10/advocating-against-andro...

In Anvil I try to follow Square's approach, e.g. keep components as viewgroups and use a custom backstack to manage them as needed (e.g. back/home navigation, multi-pane layouts etc). Then you get just one activity per application and it's a big relief.

zserge··on Anko – Pleasant Android development in Kotlin
Almost correct. I never thought of this kind of syntax sugar initially. But technically (and people posted an issue about it) it's possible to generate functions like linearLayout() etc from android.jar for Anvil/Java. This will work with Anvil/Kotlin as well.

I plan to keep v<Class> anyway because it works nice with custom views when there is no generated syntax sugar.

zserge··on Anko – Pleasant Android development in Kotlin
Oh, so Anko and Koan is the same project? Stupid me, I wondered what happened to Koan when I saw Anko first (and I didn't think of an anagram).
zserge··on Anko – Pleasant Android development in Kotlin
Let me try to answer it. I'm sure that I won't change your mind, but when I published Anvil (a similar library for Java) - I got lots of questions like yours.

- XMLs are not type safe, I can type any tag name in there, and I can set almost any value to my attributes - AAPT won't even notice (yes, Android Studio is much smarter these days, it may give a warning, but it won't be a compiler warning, so it won't be in your automated build logs. You will also miss it when using other text editor or IDE). I can put a view inside another view (not a viewgroup) - and it will pass as well. Since we waste CPU time on XMLs preprocessing - it would be nice if they also warned us about our errors at this stage, not crashes in runtime.

- The file hierarchy is terrible. All XMLs must be in the same folder, no nested folders. Having a large project makes you have dozens of XMLs on the same layer of hierarchy. Since we have OS with directories - it would be nice to use that feature like we use it for java packages.

- There are some styles, but they are too limited comparing to, say, CSS. If one ever tried LESS or SASS - he will love the mixing, variables, calculated expressions etc. It's fast to write, it's easy to read, it's reusable. You don't have to jump around multiple closely related files to tie it all together in your head. You have them in one place. Since XMLs are processed - it would be nice if I could write something like "android:background=darken(@color/mycolor, 30%)"

- There is some responsiveness, but it's too limited. If you have 3 nested views, and the topmost has margin in landscape and no margin in portrait - you have to have two (almost identical) files. Or three, if you want to use merge/include. In fact now they are all in different folders, despite they are very closely related!

- There is no way to merge with unique ids (child layout will have the duplicated ids when included twice).

- There is no mixins or macros. If I have layout with textview+button pairs - I will end up copying those two tags everywhere. If I have macros - I would write it once, and then would only type `<TextViewWithButton text="foo" buttonText="bar">` - that is supposed to be expaded into <TextView .../><Button ..../> with some texview and button attributes substituded to the given actual values.

- There is no data binding.

zserge··on Anko – Pleasant Android development in Kotlin
Thanks!

Unfortunately neither of the data binding libraries for Android worked for me, because they are either too hard to extend or too big/complex.

RoboBinding's idea is nice, but to me it's too implicit. It's really hard to tell what's happening behind the scenes.

As for the Xaramin - I would like to try it, but I run linux on my development machine, and it didn't start with Wine.

zserge··on Anko – Pleasant Android development in Kotlin
You might like Anvil: it's a declarative react-like UI library for Android. I personally use it a lot, and I normally write single-activity applications (e.g. I have my own backstack of views inside a single activity):

https://github.com/zserge/anvil

http://zserge.com/blog/anvil-2.html

Kotlin is supported as well (http://zserge.com/blog/anvil-kotlin.html)

zserge··on Gonix – Unix tools written in Go
Plan9 utils usually have less options and smaller functionality, but you can easily compose them.

"rc": I like it much more than sh for scripting. It's easier to learn and has less pitfalls.

"cat" has no options at all, it just concatenates.

"du": I like plan's "du" utility, which is easier than "find" ("du" simply lists file names recursively, while "find"... Can anyone list all the options of the find utility from memory?).

"rm" is a combination of rm and rmdir (directory is removed only if empty, unless you do "rm -r" to delete it recursively. Only two options: "-r" and "-f"

"tar" is a simple way to do recursive copying instead of cp, scp etc

"sleep" takes seconds only as an argument, but it can be a floating point (no suffixes like in coreutils, e.g. "sleep 1h" or "sleep 3d")

"who" takes no options at all

I'm not really good at plan9 utils, and I still use coreutils much more, but for embedded systems I would prefer to have a tiny number of simple building bricks like "du", "cp", "rm", "tar" etc, and a few smarter commands like awk/sed/grep/rc. I like toybox a lot, but if only that had an rc shell..

zserge··on Gonix – Unix tools written in Go
It would be cool to have a "busybox" alternative targeted at Plan9 commands. I personally find Plan9 utils much more logical (and easier to implement!). Something like 9base from suckless, but as a single binary and hopefully in a more modern language (most of the code like sam or rc is not so easy to understand).
← PreviousPage 5 of 7Next →