Skip to content

Comment on Access Control in Swift

Comments

It seems that they have chosen a default (internal, though I don't know how to interpret how "most of the time" works) which is similar to the default modifier in Java. It seems, though, that java's default modifier was maybe ill-chosen, as private and public modifiers seem far more prevalent than no modifier (which means that the default modifier is used) in java code.

It's like "protected" access, in Java's terms. Subclasses can't access the default members in Java. That is why it is so rarely used. It was oddly restrictive, and didn't seem like it made much sense in most cases. I don't find this as a bad decision, in Swift. Since you don't normally want to expose the internals of your classes, this was a good choice.

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscon...

I think you might have gotten it wrong?

I think it (Swift's internal/default) is more like "package-private" in Java.

It looks almost exactly like C#'s internal:

http://msdn.microsoft.com/en-us/library/ms173121.aspx

ChrisLattner talks about the java in this recent post if you have access to the apple dev site.

https://devforums.apple.com/message/1010693#1010693

It seems, though, that java's default modifier was maybe ill-chosen, as private and public modifiers seem far more prevalent than no modifier

My impression is that people often simply don't know exactly what the default modifier does, whereas they're more confident in the behaviour of public and private.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.