Do iOS development, will inevitably take over others touched code, before done some outsourcing projects, is a function of others have finished early, then I will need to be here before then task continues to develop, believe a lot of friends at work, too, will then write someone else’s code, then every time, I believe you will like me, Looking at the heart of ten thousand grass mud horse ~ ~ ~ drifting, and then had to silently fill the pit. Of course, the same code you write may be read by others in the future, so EVERY time I see the following code, I will definitely scold a lot. If you want to write your code in the future less people scold, at least don’t write the code below… High energy ahead
- Third party libraries are used everywhere in the project — such as AFN. We will inevitably use third party libraries in our projects. Third party open source contributors do a great job for us, thank them. Another minor concern with using third-party libraries is that as the project progresses, it can be costly to replace third-party libraries if you have relied on them throughout the project. The most common network request in the project is to use AFN to complete the network request. You said that using this third party library to complete the network request must be the correct choice, but…… Network requests are basically
Send,GET,POST requests
.Download files, upload files
For these four common requirements, can’t you encapsulate several interfaces by yourself when you use AFN, and then the network requests in the project will use these interfaces encapsulated by yourself, and it will be better to directly change these interfaces when changing the network request library in the future? Instead of having to change all the web requests in every project next to each other (which is almost impossible, since many projects still use ASIHTTPRequest), I have seen the entire project developed using SWIFT and the web request library using AFN. All network requests in the project were completed directly using the AFN interface. As a result, the project decided to change to Alamofire, and then… You know,
@interface ZJHttpTool : NSObject /** ** send a GET request ** @param URL request path * @param params request parameter * @param success callback after successful request (please write to this block what you want to do after successful request) ** @param failure callback after a failed request (please write to this block what you want to do after a failed request) */ + (void)get:(NSString *)url params:(NSDictionary *)params success:(void (^)(id responseObj))success failure:(void (^)(NSError *error))failure; + (void)post:(NSString *)url params:(NSDictionary *)params success:(void (^)(id responseObj))success failure:(void (^)(NSError *error))failure; . @endCopy the code
- Naming conventions Ever heard of prefixes for class names in OC? Well, I’m used to defining a global constant file in each project named
constant.h
… Can you add a class prefix? Although it doesn’t have much impact on the project as a whole, it’s really annoying to have a class name that doesn’t follow the rules. Have you ever heard of using English variable names? You said the computer world is the English world is true, everyone advocates variable naming in English. So what do those patriots who use pinyin to name them think, have seen a lot of themyouxiangzhanghao, banjibianhao, xingmin, xingbie ...
, you say these common nouns in English you write a pinyin is really let a person can not look at ah, can only let me scold — must be English is too weak silly X write code… Well, there are some people who strictly abide by the naming rules, so the variable names in the project are all in English. But ah, ah, ah, for my poor students who have passed cet-6, look at you, the advanced naming depends entirely on the dictionary. (There is nothing wrong with computers.)Anticoagulant, tranquilizer... A bunch of names and technical terms
These things are unbearable ah, look at the code is to look up the dictionary, here I hope to use pinyin, even if others scold me to use pinyin silly force… - This is really a very, very large number of code to read the class file, a controller opened, saw the most close to 4000 lines, my god, how people live, the most frustrating is, Take a look at —- a viewDidLoad of more than 2000 lines of code…… It’s a good practice to manage constants in a single file, but you have thousands of constants in a single file. Really want to cry no tears ah…
- Notifications are all over the place and notifications are really useful in iOS development, you can send values across the interface, you can send values to multiple objects at once. However, it is not used in this way, oh, all pages pass values in reverse, feel the most convenient notification, a post to publish a notification, and then register notifications everywhere in the project to listen, I don’t know how these people do it correctly remove notification listener… What’s more, the name of the announcement is written casually… Notifications are great, but be careful where you use them
- Magic numbers all over the place. I’ve seen it all over the place in this project, most commonly when setting up the frame, and maybe as noted, all the numbers are the developer’s, and it feels like it makes sense when you’re writing the code
Self.searchbar. frame = CGRectMake(0, 22, 320, 44);Copy the code
- Everywhere is the proxy The above said people use notice everywhere, there is someone use proxy everywhere, who need to reverse the value or respond to certain actions, all write a agreement first, and then achieve an agent, I have seen a header file above comply with more than ten of the agreement, then these agreements and basically only one agent method, Even worse, a protocol contains many, many proxy methods, all marked optional… And then call it directly where needed
Like this, there are a lot of protocols in the controller, many methods don't know which protocols are in, at least you need to add a comment or something... - (void)saveBtnDidTouched {// Agent 1... } - (void)sexDidChanged {// proxy two... } - (void)downloadDidFinished {// Agent three... }Copy the code
- Feel free to reference third-party libraries — and then modify some of them yourself before you dare pod update them
- On cross-page pass, you’ve seen a project where all the cross-page reverse passes are passed using singletons, and then many places are modifying and retrieving the same properties of the singletons. Cry when you get code like this… You have no idea where this value is going to change. In addition, there is a disgusting transfer value, this kind of person is speechless, the need for cross-page transfer values are all written to the local file, and then directly read the value of the file in other pages… Genius!
- A class to implement many page functions some people code reuse concept is really too strong, do not want to write a little more code, so, a custom UITableViewCell inside a variety of judgments, to achieve a lot of control hide and position adjustment… All kinds of cells that look different are put into the same cell file to manage.
- Use black magic everywhere +load this kind of people, do not know is to show how knowledgeable or what, project opportunity, directly write a system class extension, then rewrite +load method, continue to high energy, use black magic exchange system method… When you find yourself clearly inherited from the control of the system to write code, why why, the effect is very strange, and then you begin to doubt life. I once used UINavigationController in a project, because I customized the back button, and then the swiping gesture failed, so I solved the problem as before, changed the proxy of the gesture, and found that it would not work as well as before anyway. Eventually, a lengthy inspection revealed that someone had used Runtime to change the gesture proxy in a previous file to achieve the effect of sliding back full screen…
Originally was used to ridicule the recently seen strange code, but write to write do not want to continue to ridicule, anyway, eventually still want to continue to fill the pit, but, I hope you will not write so weird code out, because —– is really will be scolded