obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Code Cleanup / function overloading

Open dredhorse opened this issue 3 years ago • 3 comments

Taken from: https://github.com/blacksmithgu/obsidian-dataview/pull/1283

Also I have in issue with the code (perhaps) containsword doesn't behave like contains. containsword is case insensitive, contains is not (?) as this isn't documented, we have at least icontains and econtains . (so what is the difference between those functions?) so let's say we need icontains and econtains, do we have icontainsword and econtainsword?

without looking at the code would not function overload of .contains make more sense instead of having a lot of different function where you will need to correctly define the small difference in behaviour?

I know I can figure it out, but for a noncoding user the difference between those functions could probably be better described by having the same example with the different functions to show where the real difference is in one place. for example: contains("Hello", "Lo") = true contains("Hello", "lo") = true econtains("Hello", "Lo") = false econtains("Hello", "lo") = true icontains("Hello", "Lo") = true icontains("Hello", "lo") = true

That should probably be a contains example right before the extract part. (I'm sorry hat I can only comment atm, but I haven't had time to get my git stuff running again)

dredhorse avatar Jul 25 '22 15:07 dredhorse

Differently named functions is the most terse way to represent the different contains variants:

  • contains is the standard "look for thing in array OR look for substring in string"
  • econtains is a niche function for working with lists of strings. contains is recursive and will search for substrings inside strings inside lists; so contains(["hello", "goodbye"], "hell") = true. If you only want exact string matches, use econtains(["hello", "goodbye"], "hell") = false.
  • icontains is case-insensitive contains.
  • containsword is case-insensitive contains that additionally only matches full words (so spaces/punctuation before and after).

There could be a function overloaded variant instead, but I suspect it would be pretty verbose.

blacksmithgu avatar Jul 31 '22 19:07 blacksmithgu

but contains is case sensitive and containsword not or? shouldn't it be then icontainsword or would case sensitive containsword only be a cornercase?

dredhorse avatar Aug 01 '22 10:08 dredhorse

It would likely be a corner case. I honestly don't think many of these functions will be that popular but I might be wrong. Let's see.

AB1908 avatar Aug 01 '22 11:08 AB1908