preface

Life must be happy, don’t make the golden bottle empty to the moon. We are born with a lot of rules about what to do and what to think, and a lot of people telling us we should do and say this. And the most real thoughts and views of their own hearts have been slowly obliterated, leaving only a body without a mind. Should not be so silent, to boldly try the unknown. Writing code is the same, it is said that we programmers boring, less talk, in fact, we just want to say the words of the code to express. So you code like you want. Follow this column and leave your quirky code or statement in the comments section or on Star Github:

Github:github.com/blindmonk/S…

Class and resource files must be named however you like

💩 I believe you must have trouble with the naming of the class, we should reduce this trouble to protect our hair 👷

Good 👍 🏻

Open class caoxian666 {/*...... * /}Copy the code

Bad 👎 🏻

{/*... * /}Copy the code

Do not write comments at any time

💩 no one will read your code anyway, someone should let you fix the computer 💻

Good 👍 🏻

var niubi = 9527
Copy the code

Bad 👎 🏻

Var caoxian = 666; var caoxian = 666;Copy the code

Function and variable naming must be manipulated freely

💩 We should think less about naming so that we have more time to think about code logic and so on 🍺

Good 👍 🏻

Fun caozongziru () {/ *... */ } var abc = 1Copy the code

Bad 👎 🏻

Fun initializeView () {/ *... */ } var pageSize = 20Copy the code

Write as much code as you can on one line

💩 Many people have the ability to glance ten lines at a glance, which can greatly improve the efficiency of reading code 🤘

Good 👍 🏻

AlertDialog.Builder(context).setView(0).setTitle(R.string.dialog_title).setMessage(R.string.dialog_message).setIcon(0) .create()
Copy the code

Bad 👎 🏻

AlertDialog.Builder(context)
            .setView(0)
            .setTitle(R.string.dialog_title)
            .setMessage(R.string.dialog_message)
            .setIcon(0)
            .create()
Copy the code

The controls in your UI layout must be dense

💩 the more controls in the UI layout should be nested, so as to reflect their logical thinking ability ⛲

Good 👍 🏻

<RelativeLayout>
 <LinearLayout>
  <RelativeLayout>
   <ImageView/>
    ...
   <TextView/>
  </RelativeLayout>
 </LinearLayout>
</RelativeLayout>
Copy the code

Bad 👎 🏻

<android.support.constraint.ConstraintLayout>
 <ImageView/>
  ...
 <TextView/>
</android.support.constraint.ConstraintLayout>
Copy the code

Write code you won’t use

💩 Be prepared for a rainy day. Code is the same. Plan for the future by writing code that you don’t use 📬

Good 👍 🏻

fun countPrimes(n:Int,count:Int): Int {
    var sum  = 9527;
    return n + count;
}
Copy the code

Bad 👎 🏻

fun countPrimes(n:Int,count:Int): Int {
    return n + count;
}
Copy the code

Think ahead when writing code

💩 do not do not put me things, also do not write not sure of the code. Don’t forget to write your own Plan B 🛀

Good 👍 🏻

fun countPrimes(n: Int): Int { if (n < 0) { return -1 } else { return n + 666; } // My plan B returns 0; }Copy the code

Bad 👎 🏻

fun countPrimes(n: Int): Int { return if (n < 0) { -1 } else { n + 666; }}Copy the code

Don’t worry about exception errors

💩 Everything is under control and even if you catch an exception you do not need to report it because you may not be able to resolve it 🎃

Good 👍 🏻

try {
   ...
}catch (e: SomeException) {
   //caoxian666...
}
Copy the code

Bad 👎 🏻

try {
   ...
}catch (e: Exception) {
    reportedException(e)
}
Copy the code

Write code with clarity and simplicity

💩 any fool can write code that a machine can understand, but it takes a good programmer to write code that fools can understand

Good 👍 🏻

fun getTomorrowDate(): DateTime {
    Thread.Sleep(24 * 60 * 60 * 1000)
    return DateTime.Now
}
Copy the code