Click here to Skip to main content
15,887,746 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Nasty bug only found in production Pin
Chris Maunder28-Nov-18 4:27
cofounderChris Maunder28-Nov-18 4:27 
GeneralRe: Nasty bug only found in production Pin
Dan Neely28-Nov-18 4:34
Dan Neely28-Nov-18 4:34 
GeneralRe: Nasty bug only found in production Pin
Chris Maunder28-Nov-18 4:59
cofounderChris Maunder28-Nov-18 4:59 
GeneralRe: Nasty bug only found in production Pin
Randor 29-Nov-18 18:22
professional Randor 29-Nov-18 18:22 
GeneralRe: Nasty bug only found in production Pin
raddevus4-Dec-18 5:31
mvaraddevus4-Dec-18 5:31 
GeneralRe: Nasty bug only found in production Pin
TheGreatAndPowerfulOz12-Jan-19 6:47
TheGreatAndPowerfulOz12-Jan-19 6:47 
GeneralRe: Nasty bug only found in production Pin
raddevus12-Jan-19 12:42
mvaraddevus12-Jan-19 12:42 
GeneralReadable code, taken too far (too Swift)? Pin
raddevus19-Nov-18 10:32
mvaraddevus19-Nov-18 10:32 
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:
C#
int Add(int addend1, int addend2){
    return addend1 + addend2;
}

Of course we call it like:
C#
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:
Swift
func Add(_ addend1: Int, _ addend2: Int) -> Int{
   return addend1 + addend2;
}

You can call that method like :
Swift
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:
Swift
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):
Swift
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:

Swift
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 (String) is to and its internal name is newName.

Now, check out what the final call to that method looks like. It's like readable English but hmm....it feels so odd to be code that it makes me stumble anyways and I'm not sure it really advances understanding.
Swift
changeName(of:d, to:"Rover")


Change name of d to rover.
Cool | :cool: ? or Suspicious | :suss: ?

modified 19-Nov-18 17:12pm.

GeneralRe: Readable code, taken too far (too Swift)? PinPopular
Chris Maunder19-Nov-18 15:07
cofounderChris Maunder19-Nov-18 15:07 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus19-Nov-18 15:22
mvaraddevus19-Nov-18 15:22 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Chris Maunder19-Nov-18 16:08
cofounderChris Maunder19-Nov-18 16:08 
GeneralRe: Readable code, taken too far (too Swift)? Pin
obermd23-Nov-18 3:32
obermd23-Nov-18 3:32 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Marc Clifton20-Nov-18 0:40
mvaMarc Clifton20-Nov-18 0:40 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus20-Nov-18 1:56
mvaraddevus20-Nov-18 1:56 
GeneralRe: Readable code, taken too far (too Swift)? Pin
jsc4220-Nov-18 21:50
professionaljsc4220-Nov-18 21:50 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Dan Neely23-Nov-18 5:12
Dan Neely23-Nov-18 5:12 
GeneralRe: Readable code, taken too far (too Swift)? Pin
ajhampson23-Nov-18 8:09
ajhampson23-Nov-18 8:09 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus24-Nov-18 11:43
mvaraddevus24-Nov-18 11:43 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Gerry Schmitz23-Nov-18 12:05
mveGerry Schmitz23-Nov-18 12:05 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus24-Nov-18 11:41
mvaraddevus24-Nov-18 11:41 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Jon McKee24-Nov-18 20:56
professionalJon McKee24-Nov-18 20:56 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus25-Nov-18 5:31
mvaraddevus25-Nov-18 5:31 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Lutosław25-Nov-18 11:20
Lutosław25-Nov-18 11:20 
GeneralRe: Readable code, taken too far (too Swift)? Pin
André Pereira25-Nov-18 23:31
André Pereira25-Nov-18 23:31 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Lutosław26-Nov-18 1:00
Lutosław26-Nov-18 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.