Arc Forumnew | comments | leaders | submitlogin
4 points by aw 5065 days ago | link | parent

I think in terms of naming functions, it's a good idea to give short names to the functions you call often.

I also think that overloading or "punning" functions is fine, when it allows you to type a short name more often.

I think it's a good idea for the underlying, more primitive functions to remain available. For example, if I did want to call an intersperse with strings and have it return a list, it would nice to able to call the underlying intersperse function directly. The underlying function can be given some longer name, since you don't have to type it very often.

Eventually we start to notice some commonality among these patterns. We have a bunch of functions that could return either a list or a string. We have a bunch of functions that could search from the left or search from the right. I haven't given any thought to what the best way to express these patterns are (whether in the function name, or with prefixes, or with keyword arguments... etc.), but I don't think that some kind of declarative language ("I want to find the three rightmost characters that meet this test and return the result as a string") is necessarily a terrible idea...



1 point by akkartik 5065 days ago | link

So if I read you right, you're saying that having intersperse do something special for lists of strings is ok, and we could include a longer-named version that doesn't do the specialcase?

-----

1 point by aw 5065 days ago | link

Yeah. I think so. For example, "map" returns a string when passed a string, which strikes me as a similar situation.

I could see having a longer-named version of "map" which is the primitive, simple case, that just returns a list. So if I know I want a list I have the option of calling the longer named version, while the shorter named versions such as "map" or "intersperse" do whatever is the most common case of what I usually want.

-----

1 point by akkartik 5064 days ago | link

Makes sense, thanks for the map example.

I think I was confused because intersperse doesn't seem like a short name to me :) But of course you mean 'prime namespace real estate', which is partly about length but also about being an english word and so easier to remember.[1]

intersperse still seems weirder than map, because map just returns the type of its args, while intersperse is checking the type of elements inside its list arg.

[1] This made me also focus on the fact that testify is actually an english word - and arc is misusing it.

-----

2 points by rocketnia 5064 days ago | link

intersperse still seems weirder than map , because map just returns the type of its args, while intersperse is checking the type of elements inside its list arg.

Yeah, that's one reason I'm not sure I agree with this proposal. Fundamentally, I don't like the idea that (intersperse x (list a b c)) would return (list a x b x c) sometimes and (+ a x b x c) others.

If "string:intersperse" is common enough to be a standalone utility with a shorter name, I'd probably name it after PHP's implode(). I'd probably make it use '+ too, so that it could be used to construct lists and custom types of sequence:

  (def implode (first between seq)
    (apply + first (intersperse between seq)))
  
  (implode "?" '& ...)
  (implode "" "\n" ...)
Using '+ instead of hardcoding 'string makes less sense if you have '+ dispatch on the type of the last argument. But hey, I'm a fan of dispatching on the first arg anyway. ;)

This made me also focus on the fact that testify is actually an english word - and arc is misusing it.

How about 'checkify? ^_^ I don't actually mind word misuse, but I do kinda like the idea of reserving the term "test" for unit tests, and I suppose there are even contexts where 'testify could be used for its English meaning:

  - assertions
  - debugger interaction
  - proofs
  - simulations of belief, knowledge, perception, persuasion, etc.
  - generally, status reports, contracts, and sanity checks registered
      with some surrounding framework or compiler

-----

1 point by akkartik 5064 days ago | link

Oh I like implode, thanks. Especially if it's used in this sense in another language, that makes it closer to 'prime real estate'.

-----