关于android:如何编写垃圾代码-Android

2次阅读

共计 1847 个字符,预计需要花费 5 分钟才能阅读完成。

前言

人生得意须尽欢,莫使金樽空对月。 咱们从小就有许多规定要求着做事思考,也常有人在耳边说应该这么做应该这么说。而本人心田最实在想法和观点缓缓都被磨灭,只留下了一副没有主意躯壳。不应该就这样寂静,要大胆的去尝试未知。写代码也一样,都说咱们程序员闷、话少,其实咱们只是把想说的话用代码进行了表白。所以写代码就要得心应手。关注本专栏能够把你的奇思妙想代码或者语句留在评论区或 Star Github:

Github:https://github.com/blindmonk/ShitCode

类和资源文件命名肯定要得心应手

💩 置信你肯定对类的命名有过苦恼,咱们应该缩小这种懊恼爱护咱们的头发👷

Good 👍🏻

open class caoxian666 {/*……*/}

Bad 👎🏻

open class DeclarationProcessor {/*……*/}

任何时候都不要写正文

💩 反正没人会读你的代码,应该会有人让你修电脑💻

Good 👍🏻

var niubi = 9527

Bad 👎🏻

// 666 是依据网络名句得出:宁睡曹县一张床,不买上海一套房
// @查看: < 新闻介绍 >
var caoxian = 666;

函数和变量命名肯定要操纵自如

💩 咱们应该缩小对命名的思考,这样就会有更多工夫去思考代码逻辑等问题🍺

Good 👍🏻

fun caozongziru() { /*……*/}
var abc = 1

Bad 👎🏻

fun initializeView() { /*……*/}
var pageSize = 20

尽最大致力把代码写成一行

💩 许多人都有一目十行的能力,写成一行能够大大提高浏览代码的效率🤘

Good 👍🏻

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

Bad 👎🏻

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

UI 布局中的控件肯定要稀稀拉拉

💩 UI 布局中控件嵌套应越多越多,这样能力体现本人的逻辑思考能力⛲

Good 👍🏻

<RelativeLayout>
 <LinearLayout>
  <RelativeLayout>
   <ImageView/>
    ...
   <TextView/>
  </RelativeLayout>
 </LinearLayout>
</RelativeLayout>

Bad 👎🏻

<android.support.constraint.ConstraintLayout>
 <ImageView/>
  ...
 <TextView/>
</android.support.constraint.ConstraintLayout>

编写你不会应用的代码

💩 做人要防患未然,写代码也是一样,要编写本人不应用的代码为将来做打算📬

Good 👍🏻

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

Bad 👎🏻

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

写代码应急功近利

💩 不做没有把我的事件,也不写没有把握的代码。不要遗记编写本人的 B 打算🛀

Good 👍🏻

fun countPrimes(n: Int): Int {if (n < 0) {return -1} else {return n + 666;}
    // 我的 B 打算
    return 0;
}

Bad 👎🏻

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

不必关怀异样谬误

💩 一切都在把握之中,即便捕捉了异样也不须要上报,因为你不肯定能解决它🎃

Good 👍🏻

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

Bad 👎🏻

try {...}catch (e: Exception) {reportedException(e)
}

简洁明了的编写代码

💩 傻瓜都能写出能让机器了解的代码,而优良的程序员能力写出让傻瓜了解的代码

Good 👍🏻

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

正文完
 0