Thursday, February 2, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home C++

How Rewriting a C++/ObjC Codebase in Swift Shrank it down to 30%

learningcode_x1mckf by learningcode_x1mckf
September 7, 2022
in C++
0
How Rewriting a C++/ObjC Codebase in Swift Shrank it down to 30%
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


You might also like

C can be memory-safe – Security Boulevard

C++ Lambda Expressions Explained | Built In

C++ creator Bjarne Stroustrup defends its safety

In a current article on the Swift language  weblog, Graphing Calculator‘s creator Ron Avitzur recounted how his choice to totally rewrite his app in Swift allowed him to shrink its codebase all the way down to 30% of its unique dimension, bettering maintainability and readability whereas not shedding efficiency.

Graphing Calculator is an app that makes it doable to create operate graphs in two and three dimensions. Initially created in 1985, it was bundled by Apple with the unique PowerPC computer systems, later moved on to stay as an unbiased product obtainable for macOS, Home windows, and iOS. After 35 years of continued growth, one of the best ways ahead, says Avitzur, was a full rewrite, though that is all the time a serious feat, requiring a whole lot of work.

Legacy code embodies a long time of hard-learned classes […]. Whereas a contemporary begin may be aesthetically satisfying, it creates an infinite floor space for bugs. In a typical dot launch, focusing testing on new options is simple. With a whole rewrite, the whole lot is new.

Graphing Calculator used a set of various languages and stacks, together with C++ and Goal C/C++, Lex and YACC, AppKit and UIKit, and OpenGL. All of this morphed right into a coherent Swift codebase utilizing SwiftUI and Metallic over 18 months with a discount of the road depend from 152,000 strains to 29,000.

Much less code means much less to debug, much less to learn and perceive, and that alone makes the port simpler to take care of. Utilizing SwiftUI, view controllers go away solely: an enormous win for declarative programming over crucial.

Among the many main advantages of the rewrite, Avitzur mentions the discount in boilerplate code, which made the logic and the which means of code clearer; using worth sorts in assortment sorts, which made it easier to cause about them; the conciseness introduced by sort inference, enumerations, closures, and Swift concurrency.

The largest problem, then again, was conserving the identical degree of efficiency compared to a codebase which had been extremely optimized for over 30 years.

As Avitzur explains in a Twitter thread, the primary port paid a 10x penalty when it comes to efficiency. He might cut back it all the way down to 2x by disabling all Swift runtime checks and utilizing vDSP for innermost loops. One remaining problem, although, is the cost of automatic reference counting on tree traversal, for the reason that Swift compiler has no approach to specify {that a} given portion of the code won’t change any reference counts.

General, says Avitzur, each Swift and SwiftUI have lived as much as their guarantees and opened up the potential for contribute parts of the code in type of stand-alone Swift Packages for mathematical typesetting, modifying, numeric and symbolic computation, and graphing.





Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

C can be memory-safe – Security Boulevard

by learningcode_x1mckf
February 1, 2023
0
C can be memory-safe – Security Boulevard

The concept of memory-safe languages is within the information currently. C/C++ is known for being the world’s system language (that runs most issues) but in addition notorious for being...

Read more

C++ Lambda Expressions Explained | Built In

by learningcode_x1mckf
February 1, 2023
0
C++ Lambda Expressions Explained | Built In

One of many new options launched in trendy C++ ranging from C++ 11 is the lambda expression.It's a handy solution to outline an nameless operate object or functor....

Read more

C++ creator Bjarne Stroustrup defends its safety

by learningcode_x1mckf
January 31, 2023
0
C++ creator Bjarne Stroustrup defends its safety

The creator of C++, Bjarne Stroustrup, is defending the venerable programming language after the US Nationwide Safety Company (NSA) just lately really helpful towards utilizing it. NSA advises...

Read more

Solid Sands and Rapita target hard to do C++ code analysis … – eeNews Europe

by learningcode_x1mckf
January 30, 2023
0
Solid Sands and Rapita target hard to do C++ code analysis … – eeNews Europe

Solid Sands and Rapita target hard to do C++ code analysis ...  eeNews Europe Source link

Read more

Bjarne Stroustrup Defends C++ As Safe

by learningcode_x1mckf
January 29, 2023
0

It is not stunning to search out the creator of a language defending the language they created and so it's with the newest paper from Bjarne Stroustrup. Is...

Read more
Next Post
“Please, for the love of all things holy, find a different color than orange” – Hacking with Swift

“Please, for the love of all things holy, find a different color than orange” – Hacking with Swift

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

JavaScript developers: Here are the top trends and tools

JavaScript developers: Here are the top trends and tools

January 16, 2023
Time limit for notify – JavaScript – SitePoint Forums

Other ways to replace a table row? – JavaScript – SitePoint Forums

September 9, 2022
Manage Attributes in Python – Real Python

Manage Attributes in Python – Real Python

November 9, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • Java :Full Stack Developer – Western Cape saon_careerjunctionza_state
  • Pay What You Want for this Learn to Code JavaScript Certification Bundle
  • UPB Java Jam brings coffeehouse vibes to Taylor Down Under | Culture

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?