0

My background is computer science and im trying to properly document some of my code.

I have a list of strings and I want to mathematically denote a check if the string is empty. The string exists, it might just be empty. Here $S$ is my string and $l$ my list.

I dont think i can denote it as if $ S \notin \emptyset$ then because an empty string is still a string? quoting wiki empty string

The empty string should not be confused with the empty language ∅, which is a formal language (i.e. a set of strings) that contains no strings, not even the empty string

Or is it as simple as if $|S| = 0$ then

The wiki also mentions the empty string is denoted with ε or sometimes Λ or λ. I assume that if $S = \epsilon$ then is not correct.

Rien
  • 101
  • 2
    Assuming $|\cdot |$ is in reference to the length of the string, then "if $|S|=0$..." is fine. Alternatively, using whatever notation for the empty string you like "if $S=\varepsilon$ (where $\varepsilon$ is the empty string)..." is fine too. Words are fine as well, just saying "if $S$ is the empty string..." – JMoravitz Mar 27 '20 at 11:53
  • Since you are documenting code specifically... I would refer to it as it is in whatever language you are coding... E.g. for Java, if (myString.isEmpty()) or in JavaScript, if (myString === "") – JMoravitz Mar 27 '20 at 11:55
  • @JMoravitz i prefer to document pseudo code so its not language bound – Rien Mar 27 '20 at 12:01
  • 3
    In which case, use a sufficiently "pseudo-codey" way of writing it... if myString is empty seems perfectly acceptable, readable, and non-ambiguous to me – JMoravitz Mar 27 '20 at 12:04

1 Answers1

1

$\epsilon$ is a property of languages. This is more computer science theory rather than programming. You'll never see $\epsilon$ used in programming.

That being said, I'm not sure I fully understood your question, but there isn't a need to comment out simple stuff like this

For example, if you are using Python:

if (x):
    print("X is not empty")

In python or most languages, to denote a string is empty, you may declare it as such:

x = ""

This tells you two things.

a) It is a string since it is surrounded by quotes

b) The string is of length 0 since there is nothing between the quotes

There is no need to comment stuff like this. Anyone with a CS background would be able to understand what you are doing here.

K Split X
  • 6,565