Diagnosis certificate of three fake hospitals for mental diseases in Xihong City
The name | I just called Tom. Why | Families don’t | Cleanliness section |
---|---|---|---|
Date of diagnosis | July 7, 2017 | Attending physician | Liu Jifen |
I have been in this line of work for some time. I’m an “iOS” junior developer. Why was iOS created? Because there are many versions of iOS. There are IOS developers, there are IOS developers, and I’m the average IOS developer. I believe there are many people who would say that this person is sick, right? It’s not all the same! But I don’t think so. If your name is Liu Jifen, and the household registration officer is also a casual person, write you as “Liu Integrin”, then your life will be in a mess. The case of iOS is trivial, but it demonstrates your respect for the industry you work in.
From the beginning of OC to now, the coding format is the place I pay the most attention to. (not to mention the code level) I never ask others how to write the format, I just ask myself, according to apple code format game rules, until YESTERDAY I saw Ta wrote a code…
-(NSString*) huoquriqi:(NSDate*)d{NSString*riqi =@"";
NSDateFormatter* df= nil;
if(d ! =nil ) {if (df== nil)
{
df=[[NSDateFormatter alloc]init];
}
[df setTimeStyle:
NSDateFormatterFullStyle];
[df setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
[df setLocale:[NSLocale currentLocale]];
riqi =[df stringFromDate:d];
}
return riqi;
}
Copy the code
This is a utility class method that I need to use. The most conscientious is to write a comment “get date”, and then from method name to variable name to format. Why “*” after some add space and some do not add, there is a plus before some add behind? Why newline formatting is so arbitrary. This code is readable, but the readability is 0, for anyone who has the patience to read it. I had to modify it.
/* * get the date * * @param date Pass the date date * * @returnFormat date */ - (NSString *)getFormatTime:(NSDate *)date {NSString *returnValue = @"";
NSDateFormatter *dateFormatter = nil;
if(date ! = nil) {if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc]init];
}
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
[dateFormatter setLocale:[NSLocale currentLocale]];
returnValue = [dateFormatter stringFromDate:date];
}
return returnValue;
}
Copy the code
It’s not that my code format is too standard, at least it’s not too broken for other developers to see. The most common public format, the one apple uses officially. It’s kind of a game.
## The doctor advised
- 1. Class naming
Let’s start with how classes are named. I’ve seen a lot of engineers named after themselves. This is not necessary, but liuJifenViewController.h may be confusing to others when they see it. If I change it to ChatViewController.h it might be a little bit easier to read. It is best to use the abbreviation of the company name, such as txChatViewController.h. Adding prefixes is optional for App developers because they don’t have to worry about class name duplication. But for SDK developers, if a third party integrates with your SDK, but the class name is repeated, that would be embarrassing and unprofessional.
- 2. Header file declaration
What does this say, you wonder? In fact, there is a saying. Such as function # import < AVFoundation/AVFoundation. H >, # import < CoreLocation/CoreLocation. H > together, such as the controller related together and so on. It is best to add relevant comments at the end so that others can modify them later. Why do we need to. And why! ?). Ex. :
# import < AVFoundation/AVFoundation. H > / / audio
# import < CoreLocation/CoreLocation. H > / / location services
#import "Gzip. H "// compress
#import "txChatViewController.h" // chat interface
# import "TXChatMessageTableViewCell. H"/news/cell
Copy the code
- 3. Add a proxy
Believing this, most people ignore “space”. I’ll show you
@interface TXChatViewController()<UITableViewDelegate,UITableViewDataSource>
Copy the code
Is that normal? There is no functional impact. Please look carefully at apple’s API documentation, there will be __ double __ Spaces!
@interface TXChatViewController() <UITableViewDelegate, UITableViewDataSource>
Copy the code
The first is a space after “()”, the second is each proxy comma “, “also followed by a space.
- 4. Declare global variables
For the most part:
@property(nonatomic,strong)UITableView*myTableView;
Copy the code
2. To write faultily:
@property (nonatomic, strong) UITableView *myTableView;
Copy the code
By contrast, is it more beautiful?
- 5. The method name
Method name is actually very important, all things are methods, method name is not easy to understand, it also makes hair all things.
-(UIButton*)button:(NSString *)string frame:(CGRect)rect color:(UIColor*)color{
UIButton*button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = rect;
button.backgroundColor = color;
[button setTitle:string forState:UIControlStateNormal];
return button;
}
Copy the code
It was originally fun to create a Button factory method. After seeing this factory, I had the idea of leaving this factory.
- (UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title backgroundColor:(UIColor *)color
{
UIButton *kbutton = [UIButton buttonWithType:UIButtonTypeCustom];
kbutton.frame = frame;
kbutton.backgroundColor = color;
[kbutton setTitle:title forState:UIControlStateNormal];
return kbutton;
}
Copy the code
Add comments if necessary.
- 6.if else
if(ture)
{
do something
}else
{
do something
}
Copy the code
The official written
if(ture) {
do something
} else {
do something
}
Copy the code
- 7.#pragma Mark –
I don’t recommend writing too much code in one Controller, which is difficult to manage and highly coupled, but using #pragma Mark – is a good way to do this if the business can’t be detached.
#pragma mark - UI rendering
#pragma mark - TableView DataSource
#pragma Mark - Web request
#pragma mark - Factory method
#pragma mark - Utility class
Copy the code
## Diagnosis
In fact, this is not the criterion of a good programmer, programming thought is the most important. But code is like a coat, and it’s easy to judge people by their looks.
- Attending physician: Liu Jifen (seal)
- Date: July 07, 2017
My code format is for reference only, not a standard. I look forward to your advice.