What is Beautiful Code?

What is Beautiful Code?

What is Beautiful Code?

  1. Beautiful code is clean, well-organized, and simple to upgrade.
  2. Easy to read, understand
  3. Easy for modification?
  4. Coding standards save you a lot of time

How to Write Beautiful Code ?

  1. Name of Variable and Method : Variables name must give meaning of variable , for example height for cell , you should write it like?:?

var cellEstimateHight = 152

Method name must be verb (meaning what this function is do ) like if you are calculate any process , that is should reflect to the Method Name . for example :

func calculateRectangle(sideA : Double, sideB: Double) -> Double{ }

2- Organization of your workspace :?

?? You have to orange your project depend on functionally , create groups of files that relate to each other.?like all view model in one group , all helpers in one group .

3- Local Values and Global Values : Firstly you have clear perspective what is global and what is local variable for the current scope.

4- Constants : Constants are pieces of information that don’t have much value so you shouldn’t pay attention to it. you should do is to create a file with constants, create a coding standard for naming constants, group them using marks, and then use them in the classes. One more benefit of constants is that you can reuse them .?

5- Class size : a class shouldn’t be longer than 300 lines, without comments, but there will be exceptions, of course. Small classes are much easier to understand, manage, and change.Readability should always be the priority relative to class size. Your functions should also be small, easy to read and understand. You should have a maximum number of lines for function, and if the function has more lines than allowed, you should refactor it.?

6- Design patterns : Each pattern is like a blueprint that you can customize to solve a particular problem in your code, and after a little bit of practice, quite easy to understand and implement. Design patterns make communication between developers more efficient. Software professionals can immediately picture the high-level design in their heads when they refer to the name of the pattern used to solve a particular issue.

7- Code review : While the primary purpose of code reviews should be functionality, we also need to take care about readability and organization of the code. Some tools can help you with code reviews like SwiftLint or Tailor.



要查看或添加评论,请登录

Angelo Saber的更多文章

  • Identity and Lifetime in SwiftUI(Part 1)

    Identity and Lifetime in SwiftUI(Part 1)

    onAppear Life cycle of SwiftUI, When SwiftUI has created a view, swiftUI will create an identity for every view that…

社区洞察

其他会员也浏览了