hyperoslo / android-playbook Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Standardize how we do bracketing in general and ifs in particular.
//oneliners
if (foo) doSomething();
else doSomethingElse();
//no brackets
if (foo)
doSomething();
else
doSomethingElse();
//brackets
if (foo) {
doSomething();
}
else {
doSomethingElse();
}
Never hardcode color/textColor/textSize in XML layout. (source code is not allowed either)
Use styles, but don't combine layout related attributes. Such the following
<item name="android:layout_width">match_parent</item>
For resources names (both file names & entry names) such as layout, drawable, styles and color, use prefix, if it's a project comprises multiple modules, to avoid naming collision.
I'm guessing we all agree on using spaces, not tabs, for indentation, right? Good. 👍
However, while the Java convention for indentation is four (4) spaces, I personally think that's a bit overkill. Two spaces for indenting code blocks actually feels more readable to me and also keeps lines shorter (so I guess it sort of ties into #3 in that sense). Would love to hear your thoughts on this.
And I'm sure there are more things to application structure than just packages. 😃
What do you think about the formatting for data classes ? Which one do you prefer ?
data class ProductColorBlock(val title: String, val description: String, val products: Array<Product>,
val colors: Array<String>, val link: String)
vs
data class ProductColorBlock(
val title: String,
val description: String,
val products: Array<Product>,
val colors: Array<String>,
val link: String
)
Per the current guidelines, we should “always” lazily initialize member variables. However, I'm not sure if this is a good idea. I agree that we should lazily initialize final members that cannot be initialized in a constructor (quite common in Android, due to the framework not being available until a hook method like onCreate
has been called), and in those cases the lazy
delegate is awesome. But for cases where you can directly initialize members in a constructor (init { ... }
) or even directly when declaring it, I prefer those methods.
As far as I can see, there are two main ways of doing null
checks in if
statements and the like:
fun main(args: Array<String>) {
val swag: String? = null
// The King of Rock way
if (swag?.isNotBlank() ?: false) {
println("Hello, world!")
}
// The standard/Java way
if (swag != null && swag.isNotBlank()) {
println("Hello, world!")
}
}
Which one do you prefer? Albeit a teensy bit strange, I definitely think I prefer the second example with the Elvis operator.
For example:
CommentView
)?mSubmitButton
)?Static object could be recycled when the app is in the background at any time. If the states of the static object is changed. Such changing will be lost.
What do you think @Damian-Lopata @ealmdahl @sindrenm @jeantuffier
It would be nice to have naming conventions, application structure conventions and version conventions, as well as guidelines and walkthroughs as to how to create new modules in Android Studio, how to handle deployment, where to deploy etc. 😃
I propose to avoid using butterknife. Because they can't be used in modules, which means if we are going to refactor some code as a reusable module, it would be painful.
It's supposed to be relatively simple to automatically test Android apps these days. Let's dig into that and see if we can figure out some good conventions and best practices, then jot them down here for future reference. 😃
Particularly with regards to capitalization. Use the textAllCaps
property for TextViews for relevant views?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.