How do programmers practice code reuse

前端 未结 14 1254
天涯浪人
天涯浪人 2021-02-13 14:14

I\'ve been a bad programmer because I am doing a copy and paste. An example is that everytime i connect to a database and retrieve a recordset, I will copy the previous code and

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 14:42

    to get code reuse you need to become a master of...

    1. Giving things names that capture their essence. This is really really important
    2. Making sure that it only does one thing. This is really comes back to the first point, if you can't name it by its essence, then often its doing too much.
    3. Locating the thing somewhere logical. Again this comes back to being able to name things well and capturing its essence...
    4. Grouping it with things that build on a central concept. Same as above, but said differntly :-)

提交回复
热议问题