completely-unscientific-benchmarks icon indicating copy to clipboard operation
completely-unscientific-benchmarks copied to clipboard

Swift "naive" impl contradicts the philosophy

Open rex-remind101 opened this issue 4 years ago • 2 comments

The README states

We define the "naive" implementations as those which a developer with enough experience in a given language would implement as a baseline "good enough" solution where correctness is more important than performance.

Yet the Swift Language Guide, which relatively speaking a developer with any experience will spend some time glancing at clearly states:

The additional capabilities that classes support come at the cost of increased complexity. As a general guideline, prefer structures because they’re easier to reason about, and use classes when they’re appropriate or necessary. In practice, this means most of the custom data types you define will be structures and enumerations.

https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html

Yet the impl uses classes exclusively contradicting the above two notions https://github.com/frol/completely-unscientific-benchmarks/blob/86c455f2dfdfc9637dc66760a6d86571dad7cefe/swift/Sources/naive/main.swift#L4

rex-remind101 avatar Sep 23 '19 22:09 rex-remind101

@rex-remind101 good catch! May I ask you to submit a PR?

frol avatar Sep 24 '19 05:09 frol

Nodes need to be moved a lot, so I wouldn't use a struct for it. Also it doesn't build if you try to use a struct:

error: value type 'Node' cannot have a stored property that recursively contains it

Cyberbeni avatar Oct 10 '20 22:10 Cyberbeni