Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Readable code, taken too far (too Swift)?

Readable code, taken too far (too Swift)?

Scheduled Pinned Locked Moved The Weird and The Wonderful
learningcsharpswiftioscom
35 Posts 16 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lutoslaw

    IMHO it's requiring coders do what's basically IDE's job. See the "Parameter name hints" in this Idea manpage: View code reference info - Help | IntelliJ IDEA[^]

    A Offline
    A Offline
    Andre Pereira
    wrote on last edited by
    #17

    Quote:

    IMHO it's requiring coders do what's basically IDE's job.

    Ding ding, we have a winner. Did not expect this from Apple.

    L 1 Reply Last reply
    0
    • A Andre Pereira

      Quote:

      IMHO it's requiring coders do what's basically IDE's job.

      Ding ding, we have a winner. Did not expect this from Apple.

      L Offline
      L Offline
      Lutoslaw
      wrote on last edited by
      #18

      Why Apple? Idea is Jet Brains'.

      A 1 Reply Last reply
      0
      • L Lutoslaw

        Why Apple? Idea is Jet Brains'.

        A Offline
        A Offline
        Andre Pereira
        wrote on last edited by
        #19

        The topic is on Swift language, not a particular IDE. And for the record, programmers at Apple are old-school idiots who think syntactic sparseness is compatible with security code worked by other 5000 people.

        L R 2 Replies Last reply
        0
        • R raddevus

          I'm learning Swift. It's an interesting new(er) language that has some interesting new features. Functions Have External Param Names One of those features is the naming of external function params. Background Most of us are accustomed to named (internal) params. This is analogous to what we have in C# like the following:

          int Add(int addend1, int addend2){
          return addend1 + addend2;
          }

          Of course we call it like:

          Add(2,3);

          Those internal params are the names we use inside the function body. That all makes sense. What About Swift? But in Swift you can also name the external params. Actually, you have to name them in your function definition unless you use an underscore to tell the compiler you're not using an external name. Here's the same function defined in Swift:

          func Add(_ addend1: Int, _ addend2: Int) -> Int{
          return addend1 + addend2;
          }

          You can call that method like :

          Add(2,3)

          Magical Underscore However, if we do not supply the underscore, then we have to give the external param a name too, like the following:

          func Add(a1 addend1: Int, a2 addend2: Int) -> Int{
          return addend1 + addend2;
          }

          So now you have to call the Add function like the following (or it will fail to compile):

          Add(a1:2, a2:3)

          All That Culminates In This The very good book I'm reading to learn Swift[^] has an example like the following:

          func changeName(of d:Dog, to newName:String) {
          d.name = newName
          }

          What changeName Does The changeName function takes a Dog class and changes it's name property to the value that is sent in the 2nd param (String). The external variable for the first param (of type Dog) is of and the internal name of that same param is d. The external name of the 2nd param (

          R Offline
          R Offline
          Rob Grainger
          wrote on last edited by
          #20

          Smalltalk had similar readability, achieved differently. In this case, an object kennel may define a method changeNameOf:To: would be invoked as follows:

          kennel changeNameOf: d To: 'Fido'.

          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

          R 1 Reply Last reply
          0
          • R Rob Grainger

            Smalltalk had similar readability, achieved differently. In this case, an object kennel may define a method changeNameOf:To: would be invoked as follows:

            kennel changeNameOf: d To: 'Fido'.

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            R Offline
            R Offline
            raddevus
            wrote on last edited by
            #21

            Rob Grainger wrote:

            Smalltalk had similar readability, achieved differently

            Interesting. So what you're saying is that Swift is trying to copy syntax that is used by a 46 year old language. :laugh: Just kidding.

            R 1 Reply Last reply
            0
            • A Andre Pereira

              The topic is on Swift language, not a particular IDE. And for the record, programmers at Apple are old-school idiots who think syntactic sparseness is compatible with security code worked by other 5000 people.

              L Offline
              L Offline
              Lutoslaw
              wrote on last edited by
              #22

              My point was that language designers spent time to add a future which enforces some stupid rule on developers, instead spending that time implementing an IDE plugin which does the job (likely faster and better than developers anyway). Because everybody uses IDE nowadays, right? Uhm... wait. And for the recored, no-single-liners and no-assigment-in-comparison policies suddenly started to make sense... idiots.

              1 Reply Last reply
              0
              • R raddevus

                I'm learning Swift. It's an interesting new(er) language that has some interesting new features. Functions Have External Param Names One of those features is the naming of external function params. Background Most of us are accustomed to named (internal) params. This is analogous to what we have in C# like the following:

                int Add(int addend1, int addend2){
                return addend1 + addend2;
                }

                Of course we call it like:

                Add(2,3);

                Those internal params are the names we use inside the function body. That all makes sense. What About Swift? But in Swift you can also name the external params. Actually, you have to name them in your function definition unless you use an underscore to tell the compiler you're not using an external name. Here's the same function defined in Swift:

                func Add(_ addend1: Int, _ addend2: Int) -> Int{
                return addend1 + addend2;
                }

                You can call that method like :

                Add(2,3)

                Magical Underscore However, if we do not supply the underscore, then we have to give the external param a name too, like the following:

                func Add(a1 addend1: Int, a2 addend2: Int) -> Int{
                return addend1 + addend2;
                }

                So now you have to call the Add function like the following (or it will fail to compile):

                Add(a1:2, a2:3)

                All That Culminates In This The very good book I'm reading to learn Swift[^] has an example like the following:

                func changeName(of d:Dog, to newName:String) {
                d.name = newName
                }

                What changeName Does The changeName function takes a Dog class and changes it's name property to the value that is sent in the 2nd param (String). The external variable for the first param (of type Dog) is of and the internal name of that same param is d. The external name of the 2nd param (

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #23

                I'll have to learn and use Swift. This year ... :~

                Press F1 for help or google it. Greetings from Germany

                R 1 Reply Last reply
                0
                • K KarstenK

                  I'll have to learn and use Swift. This year ... :~

                  Press F1 for help or google it. Greetings from Germany

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #24

                  Good luck. I started writing some of it up here at CP : iOS 12 Programming Fundamentals With Swift: Intro & Chpt1[^] I find that learning Xcode (IDE) is a barrier too. I'm definitely accustomed to VStudio and Android Studio. The odd way that you add code when a button is clicked (see article) just doesn't feel natural to me.

                  K 1 Reply Last reply
                  0
                  • R raddevus

                    Good luck. I started writing some of it up here at CP : iOS 12 Programming Fundamentals With Swift: Intro & Chpt1[^] I find that learning Xcode (IDE) is a barrier too. I'm definitely accustomed to VStudio and Android Studio. The odd way that you add code when a button is clicked (see article) just doesn't feel natural to me.

                    K Offline
                    K Offline
                    KarstenK
                    wrote on last edited by
                    #25

                    Nice. I have found a minor formatting issue. Search for "garbage" and you will see it. :thumbsup:

                    Press F1 for help or google it. Greetings from Germany

                    R 1 Reply Last reply
                    0
                    • R raddevus

                      Rob Grainger wrote:

                      Smalltalk had similar readability, achieved differently

                      Interesting. So what you're saying is that Swift is trying to copy syntax that is used by a 46 year old language. :laugh: Just kidding.

                      R Offline
                      R Offline
                      Ryan Peden
                      wrote on last edited by
                      #26

                      I suppose it helps Swift code read more like Objective-C code. That's important in this context, because Objective-C basically grafted Smalltalk's object system onto C. And so ObjC's object syntax ended up being very Smalltalk-like. I really enjoyed it in Smalltalk. I felt that it made for very readable, understandable code. It didn't work as well and ObjC because there was a huge clash between the C syntax and the Smalltalk syntax. At first, I disliked this syntax in Swift. But in the end, I decided it was just one of those things that I disliked because it was different than what I was used to. After a while, I didn't mind it so much. I find it a lot uglier in Swift than in Smalltalk, however, since in Smalltalk you don't use brackets when sending a message to an object. The Smalltalk debugging environment is also way more fun. Test driven development is fun in Smalltalk, because if you write a test that calls a method that doesn't exist yet, it's no problem. The Smalltalk debugger will yell at you, pause execution, and then give you an opportunity to implement the method before resuming execution. Like many things in life, though, it's definitely a matter of taste and opinion. Some people will never like this aspect of Swift, and I think it's completely fine for them to feel that way. :)

                      R 1 Reply Last reply
                      0
                      • R Ryan Peden

                        I suppose it helps Swift code read more like Objective-C code. That's important in this context, because Objective-C basically grafted Smalltalk's object system onto C. And so ObjC's object syntax ended up being very Smalltalk-like. I really enjoyed it in Smalltalk. I felt that it made for very readable, understandable code. It didn't work as well and ObjC because there was a huge clash between the C syntax and the Smalltalk syntax. At first, I disliked this syntax in Swift. But in the end, I decided it was just one of those things that I disliked because it was different than what I was used to. After a while, I didn't mind it so much. I find it a lot uglier in Swift than in Smalltalk, however, since in Smalltalk you don't use brackets when sending a message to an object. The Smalltalk debugging environment is also way more fun. Test driven development is fun in Smalltalk, because if you write a test that calls a method that doesn't exist yet, it's no problem. The Smalltalk debugger will yell at you, pause execution, and then give you an opportunity to implement the method before resuming execution. Like many things in life, though, it's definitely a matter of taste and opinion. Some people will never like this aspect of Swift, and I think it's completely fine for them to feel that way. :)

                        R Offline
                        R Offline
                        raddevus
                        wrote on last edited by
                        #27

                        That's a nice summary of what Swift is trying to do and I wouldn't have known any of that about it coming from smalltalk etc. I do like readable code, but I find this type of syntax almost gets in the way since things get named very oddly just to make them begin to make natural language sentences. I like things like a player object that has a bool property of hasSpecialAbility so I can do things like:

                        if (payer.hasSpecialAbility){
                        // do stuff
                        }

                        Maybe the Swift stuff will grow on me as I use it more. Only time will tell. Thanks for the great discussion.:thumbsup:

                        1 Reply Last reply
                        0
                        • K KarstenK

                          Nice. I have found a minor formatting issue. Search for "garbage" and you will see it. :thumbsup:

                          Press F1 for help or google it. Greetings from Germany

                          R Offline
                          R Offline
                          raddevus
                          wrote on last edited by
                          #28

                          Thanks for checking out my article and letting me know about that. It's something with the CP editor and the fact that they added a new Swift code setting. It seems to be a bug and I had reported it but they never got around to it. I'll check with them again.

                          1 Reply Last reply
                          0
                          • A Andre Pereira

                            The topic is on Swift language, not a particular IDE. And for the record, programmers at Apple are old-school idiots who think syntactic sparseness is compatible with security code worked by other 5000 people.

                            R Offline
                            R Offline
                            Rob Grainger
                            wrote on last edited by
                            #29

                            Wow, I hadn't seen that Apple bug you linked before. I mean seriously, most C compilers will produce a warning for that, let alone Lint-style tools. For a company in there position not to be using *at least* those on crucial code like SSL shows that they really have no respect for their users.

                            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                            1 Reply Last reply
                            0
                            • R raddevus

                              I'm learning Swift. It's an interesting new(er) language that has some interesting new features. Functions Have External Param Names One of those features is the naming of external function params. Background Most of us are accustomed to named (internal) params. This is analogous to what we have in C# like the following:

                              int Add(int addend1, int addend2){
                              return addend1 + addend2;
                              }

                              Of course we call it like:

                              Add(2,3);

                              Those internal params are the names we use inside the function body. That all makes sense. What About Swift? But in Swift you can also name the external params. Actually, you have to name them in your function definition unless you use an underscore to tell the compiler you're not using an external name. Here's the same function defined in Swift:

                              func Add(_ addend1: Int, _ addend2: Int) -> Int{
                              return addend1 + addend2;
                              }

                              You can call that method like :

                              Add(2,3)

                              Magical Underscore However, if we do not supply the underscore, then we have to give the external param a name too, like the following:

                              func Add(a1 addend1: Int, a2 addend2: Int) -> Int{
                              return addend1 + addend2;
                              }

                              So now you have to call the Add function like the following (or it will fail to compile):

                              Add(a1:2, a2:3)

                              All That Culminates In This The very good book I'm reading to learn Swift[^] has an example like the following:

                              func changeName(of d:Dog, to newName:String) {
                              d.name = newName
                              }

                              What changeName Does The changeName function takes a Dog class and changes it's name property to the value that is sent in the 2nd param (String). The external variable for the first param (of type Dog) is of and the internal name of that same param is d. The external name of the 2nd param (

                              R Offline
                              R Offline
                              Ravi Bhavnani
                              wrote on last edited by
                              #30

                              Thanks for the link to the Swift book. Do you already know iOS? /ravi

                              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                              R 1 Reply Last reply
                              0
                              • R Ravi Bhavnani

                                Thanks for the link to the Swift book. Do you already know iOS? /ravi

                                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                R Offline
                                R Offline
                                raddevus
                                wrote on last edited by
                                #31

                                Ravi Bhavnani wrote:

                                Do you already know iOS?

                                Well, not really. I've developed a few apps but not much more. Are you learning now?

                                R 1 Reply Last reply
                                0
                                • R raddevus

                                  Ravi Bhavnani wrote:

                                  Do you already know iOS?

                                  Well, not really. I've developed a few apps but not much more. Are you learning now?

                                  R Offline
                                  R Offline
                                  Ravi Bhavnani
                                  wrote on last edited by
                                  #32

                                  raddevus wrote:

                                  Are you learning now?

                                  No, I'm currently in a passionate relationship with Android and expect this to continue for several years.  There's a small chance I'll embrace iOS development if I get a Mac. /ravi

                                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                  R 1 Reply Last reply
                                  0
                                  • R Ravi Bhavnani

                                    raddevus wrote:

                                    Are you learning now?

                                    No, I'm currently in a passionate relationship with Android and expect this to continue for several years.  There's a small chance I'll embrace iOS development if I get a Mac. /ravi

                                    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                    R Offline
                                    R Offline
                                    raddevus
                                    wrote on last edited by
                                    #33

                                    Ravi Bhavnani wrote:

                                    I'm currently in a passionate relationship with Android and expect this to continue for several years.

                                    Very smart. I like Android development a lot. Probably my favorite platform right now because it reminds me of Windows dev in the earlier years. Just seems like a lot more fun. iOS has a lot of crappy stuff and Xcode (IDE) is annoying and I realy don't like the UI layout designer because it is so confusing. In Android you can get right down into the XML and the XML makes sense and is easy to deal with (which I think is rare). iOS Ui and interactions are a pain to deal with. I feel like I"m going to move something and mess up the whole layout.

                                    R 1 Reply Last reply
                                    0
                                    • R raddevus

                                      Ravi Bhavnani wrote:

                                      I'm currently in a passionate relationship with Android and expect this to continue for several years.

                                      Very smart. I like Android development a lot. Probably my favorite platform right now because it reminds me of Windows dev in the earlier years. Just seems like a lot more fun. iOS has a lot of crappy stuff and Xcode (IDE) is annoying and I realy don't like the UI layout designer because it is so confusing. In Android you can get right down into the XML and the XML makes sense and is easy to deal with (which I think is rare). iOS Ui and interactions are a pain to deal with. I feel like I"m going to move something and mess up the whole layout.

                                      R Offline
                                      R Offline
                                      Ravi Bhavnani
                                      wrote on last edited by
                                      #34

                                      I think with Swift and future tooling, iOS development will evolve to be like how Android is today.  I think the reason why iOS development is a bit fragmented today is because it has deep roots in the legacy NextStep OS, much like early Win32 development was because it had its roots in MS-DOS (on which Windows was layered).  Today, I rely on the .NET framework and Windows Forms to insulate me from Win32 APIs. Another reason I chose to start mobile development with Android is because I get to use my favorite language (C#) and IDE (VS) to build native Android apps using Xamarin.  I have a lot of well-tested, production code in C# that I would have to rewrite (and retest) in Java.  Using the native Android API from C# is a joyous experience.  The downside is VS doesn't gibe you the free Firebase tooling that Android Studio.  But I'm still crawling, and have a way to go before I use Firebase. /ravi

                                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                      1 Reply Last reply
                                      0
                                      • R raddevus

                                        I'm learning Swift. It's an interesting new(er) language that has some interesting new features. Functions Have External Param Names One of those features is the naming of external function params. Background Most of us are accustomed to named (internal) params. This is analogous to what we have in C# like the following:

                                        int Add(int addend1, int addend2){
                                        return addend1 + addend2;
                                        }

                                        Of course we call it like:

                                        Add(2,3);

                                        Those internal params are the names we use inside the function body. That all makes sense. What About Swift? But in Swift you can also name the external params. Actually, you have to name them in your function definition unless you use an underscore to tell the compiler you're not using an external name. Here's the same function defined in Swift:

                                        func Add(_ addend1: Int, _ addend2: Int) -> Int{
                                        return addend1 + addend2;
                                        }

                                        You can call that method like :

                                        Add(2,3)

                                        Magical Underscore However, if we do not supply the underscore, then we have to give the external param a name too, like the following:

                                        func Add(a1 addend1: Int, a2 addend2: Int) -> Int{
                                        return addend1 + addend2;
                                        }

                                        So now you have to call the Add function like the following (or it will fail to compile):

                                        Add(a1:2, a2:3)

                                        All That Culminates In This The very good book I'm reading to learn Swift[^] has an example like the following:

                                        func changeName(of d:Dog, to newName:String) {
                                        d.name = newName
                                        }

                                        What changeName Does The changeName function takes a Dog class and changes it's name property to the value that is sent in the 2nd param (String). The external variable for the first param (of type Dog) is of and the internal name of that same param is d. The external name of the 2nd param (

                                        D Offline
                                        D Offline
                                        Dr Walt Fair PE
                                        wrote on last edited by
                                        #35

                                        If you want to see some very readble, but nasty code, you should try Cobol or better yet, SNOBOL.

                                        CQ de W5ALT

                                        Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups