Skip to content

Commit

Permalink
Update Coding rule for formar of year part in a date
Browse files Browse the repository at this point in the history
  • Loading branch information
KhanhLD committed Feb 21, 2019
1 parent 034853e commit f4cf4c6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 61 deletions.
6 changes: 5 additions & 1 deletion eng/android/codingstyleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ public Observable<Location> syncLocations() {
}
```

### 2.14 Date format

To format the year part of a date as `yyyy`, use `yyyy`.

## 3 XML style rules

### 3.1 Use self closing tags
Expand Down Expand Up @@ -565,4 +569,4 @@ As a common rules you should group similar attributes together.
2. Style
3. Layout width and layout height
4. Other layout attributes, sorted alphabetically
5. Remaining attributes, sorted alphabetically
5. Remaining attributes, sorted alphabetically
3 changes: 3 additions & 0 deletions eng/java/coding-standard.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ If an expression containing a binary operator appears before the ```?``` in the
#### 7.5.4 Special Comments
Use ```XXX``` in a comment to flag something that is bogus but works. Use ```FIXME``` to flag something that is bogus and broken.

#### 7.5.5 Date format
To format the year part of a date as `yyyy`, use `yyyy`.

## 8 TL;DR
If you are using IntelliJ IDEA, you can import file ```java-formatter.xml``` which includes these auto-format.
Or import from
Expand Down
1 change: 1 addition & 0 deletions eng/php/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ $normalString = 'A String';
$specialString = "This is {$normalString}";
```
- There MUST be one space before and after each operator (such as `+`, `-`, `*`, `/`, `.`, `>`, `<`, `==` ...)
- To format the year part of a date as `yyyy`, use `Y`.
19 changes: 11 additions & 8 deletions eng/ruby/standard.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Rules about writing Ruby code (Standard)
# Rules about writing Ruby code (Standard)

##Layout
## Layout

##Encoding
## Encoding
* Use UTF-8 only

* Basically, do not write code that need encoding script comments
Expand All @@ -14,7 +14,7 @@
* 2-bytes characters should not be in source code, they should be in locale files.


##Basic
## Basic
* Indentation is 2 white spaces
* Do not use tab
* Do not leave trailing white spaces
Expand Down Expand Up @@ -180,7 +180,7 @@ def some_method2
end
```

##Syntax
## Syntax

* Do not use ``` () ``` in method definition
* If parameters of method are too many, break them into new lines to ensure a line has less than 80 characters. In that case we should use ``` () ``` to avoid syntax error.
Expand Down Expand Up @@ -469,7 +469,7 @@ products.each {|prod| prod.maintain!}
Clearly show intention of creating a new object
##Naming
## Naming
* Method name or variable name use ``` snake_case ```
Expand All @@ -482,7 +482,7 @@ Clearly show intention of creating a new object
* Destroy method or dangerous method should add `!` at the end, such as ``` Array#flatten! ```
When define destroy method, un-destroy method like ``` Array#flatten ``` should be defined as well.
##Class
## Class
* Avoid using class variables ``` @@ ``` unless it is really necessary
Expand Down Expand Up @@ -597,7 +597,7 @@ class SomeClass
end
```
##Exception
## Exception
* Do not use exception to control the flow. Exceptions which can be avoided should be avoided.
Expand Down Expand Up @@ -795,6 +795,9 @@ end

If mistakenly write `==` to be `=`, the comparison will return SyntaxError

## Date format
To format the year part of a date as `yyyy`, use `%Y`.

## Others

* Do not use ``` __END___ ```
89 changes: 48 additions & 41 deletions eng/swift/coding_convention.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##Swift coding convention
## Swift coding convention

###Define variables, constants
### Define variables, constants

###Common convention for variables, constants
### Common convention for variables, constants
Can be written in a single line if they have relevance.
```sh
let row: Int, column: Int
Expand Down Expand Up @@ -65,7 +65,7 @@ let text = data["text"] as String
let text: String = data["text"] as String
```

###Definition of variable
### Definition of variable
There are many ways to write definition of empty array, associative array along with their initialization so we should refer to Apple standard only.

@see [Collection Types](https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html)
Expand Down Expand Up @@ -106,7 +106,7 @@ class Hoge {
}
```
###Definition of constant
### Definition of constant
In case of variable definition, consider whether it can be defined as a constant or not. Unless it have to be defined as a variable no matter what, define it as a constant.
```sh
let notChangeString = "Hoge"
Expand All @@ -127,7 +127,14 @@ Definition of expression can be written on right-hand side.
let kGoogleAnalyticsTrackingID = NSBundle.mainBundle().objectForInfoDictionaryKey("GoogleAnalyticsTrackingID") as String
```
###String
### Date format
To format the year part of a date as `yyyy`, use `yyyy`.
```sh
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd"
```
### String
Swift / String and ObjC / NSString are two different classes. Use Swift / String for string.
```sh
// ◯
Expand Down Expand Up @@ -183,9 +190,9 @@ String(format: "%.01f", Float(someCGFloat))
// ☓ Must be converted to Float, or it will become 0.0 which is incorrect
let someCGFloat: CGFloat = 0.25
NSString(format: "%.01f", Float(someCGFloat))
```sh
```
###Numeric value
### Numeric value
Use Swift’s numerical type for Integer. In iOS SDK > API > ObjC, NSInteger, NSUInteger have been replaced by Int, UInt.
```sh
// Example
Expand All @@ -211,7 +218,7 @@ var flg: Bool?
var index: Int?
```
###nil
### nil
Nil in Swift is nil, nil in ObjC is an object pointer which does not exist. That is the difference.
You can assign nil to any data type by unwrapping variable.
```sh
Expand All @@ -224,7 +231,7 @@ let hash: [String: String?] = ["hoge": hoge, "fuga": "not nil"]
println(hash)
// -> [hoge: nil, fuga: Optional("not nil")]
```
###Function
### Function
In case return value’s data type is void, data type is omitted.
```sh
// ◯
Expand Down Expand Up @@ -273,7 +280,7 @@ func stringFromDate(date NSDate) -> String
let text = stringFromDate(date)
```
###Closure
### Closure
Do not abbreviate closure argument.
```sh
// ◯
Expand Down Expand Up @@ -344,9 +351,9 @@ let funcClosure = { (text: String) -> String in
}
```
##Control statements
## Control statements
###If statement
### If statement
Do not use ( ) for the evaluation formula after if.
```sh
// ◯
Expand All @@ -355,7 +362,7 @@ if a == b { }
// ☓
if (a == b) { }
```
###for & for-in statement
### for & for-in statement
Use for-in statement to state loop process.
```sh
// ◯
Expand Down Expand Up @@ -394,7 +401,7 @@ for temp in self.view.subviews {
}
```
###Switch statement
### Switch statement
Write break when there is no process in case-process.
```sh
switch section {
Expand All @@ -406,9 +413,9 @@ switch section {
break // do nothing
}
```
##Statement convention
## Statement convention
###Bracket
### Bracket
Write open bracket in the same line with method or control statements’ bracket.
```sh
Expand Down Expand Up @@ -440,7 +447,7 @@ else {
}
```
###Semicolon
### Semicolon
Do not write semicolon at the end of statement.
```sh
// ◯
Expand All @@ -450,10 +457,10 @@ println("hoge")
println("hoge");
```
###File ending
### File ending
Ending file by inserting line break.
###Enum
### Enum
Write enum and case by pascal case.
When case is int and sequence begins from 0, do not write data type of enum and case.
Expand Down Expand Up @@ -509,9 +516,9 @@ class NetworkManager {
}
```
##Class, Struct
## Class, Struct
###Init
### Init
In case inheriting from NSObject, state override for int, call super.init().
```sh
class ArticleData: NSObject {
Expand All @@ -528,11 +535,11 @@ class ArticleData {
}
}
```
###Convenience init
### Convenience init
TODO:
###Property
### Property
Do not use Optional Type or Implicitly Unwrapped Optional Type as property when using init to initialize.
By whether or not there is a change of property, use let or var to define.
Expand Down Expand Up @@ -576,10 +583,10 @@ class ArticleData {
TODO: didSet
###self
### self
TODO:
###Description
### Description
In case class inherited from NSObject, override description property.
```sh
class DataModel: NSObject {
Expand All @@ -596,32 +603,32 @@ extension DataModel: Printable {
}
```
##Access control
## Access control
TODO
##Delegate
## Delegate
TODO
##Protocol
## Protocol
TODO
##Extension
## Extension
TODO
##ObjC
###Id type
## ObjC
### Id type
TODO
##Deligate
## Delegate
TODO
###Define
### Define
TODO
##Macro
## Macro
TODO
##Interface Builder Outlet, Action
## Interface Builder Outlet, Action
Outlet is defined by weak and unwrap. If you want to automatically generate the property from the street board, add private modifier.
In case remove view from parent view and you want to use this view inherently, state strong instead of weak. In case you want to use this property from external class, do not add private modifier.
Expand Down Expand Up @@ -652,10 +659,10 @@ The type of action’s argument defines action’s original class.
println("button tapped!")
}
```
##Circular referenece problem
## Circular referenece problem
TODO
##Macro comment
## Macro comment
### #pragma mark
Swift
```sh
Expand Down Expand Up @@ -685,7 +692,7 @@ Build setting -> Swift Complier Custom Flags -> -DEBUG (yes, including the –D
// PRODUCTION CODE
#endif
```
##Export log
## Export log
Use NSLog for exporting log due to these standpoints.
* NSLog is thread safe, println is not.
* NSlog is exported to device console, println is not.
Expand All @@ -702,7 +709,7 @@ However, println has following merits against NSLog.
* Export appropriate string even when variable is not formatted as string.
##Singleton
## Singleton
Singleton is defined by static constant of struct.
```sh
// ◯
Expand Down Expand Up @@ -745,7 +752,7 @@ class Singleton {
}
```
##Reference
## Reference
*[The Swift Programming Language](https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html)
*[Using Swift with Cocoa and Objective-C](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/index.html#//apple_ref/doc/uid/TP40014216)
Expand Down
4 changes: 4 additions & 0 deletions vn/android/codingstyleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ public Observable<Location> syncLocations() {
}
```

### 2.14 Date format

Để format phần năm của ngày tháng dưới dạng `yyyy`, sử dụng `yyyy`.

## 3 XML style rules

### 3.1 Sử dụng thẻ tự đóng
Expand Down
2 changes: 2 additions & 0 deletions vn/php/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ $normalString = 'A String';
$specialString = "This is {$normalString}";
```
- Cần có 1 space trước và sau các toán tử như `+`, `-`, `*`, `/`, `.`, `>`, `<`, `==` ...
- Sử dụng `yyyy` để format phần năm của ngày tháng.
- Để format phần năm của ngày tháng dưới dạng `yyyy`, sử dụng `Y`.
Loading

0 comments on commit f4cf4c6

Please sign in to comment.