Flags in programming

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Flags in programming

#1 Post by PaperTronics » 25 Jun 2017 02:39

ShadowThief wrote:2. Timeout doesn't exist in XP, and ping can be used for pauses of less than one second.


I don't think many people use XP nowadays. But then again, there are some people who do and also as you described ping allows us to pause for less than 1 sec. Thanks for correcting me.

ShadowThief wrote:. For those of you without screen readers and who don't feel like copying and pasting, that's a capital i, not a lower case L. It's also worth mentioning that flags are not case-sensitive (nor are basically anything in batch except for loop variables).


What are flags? Am I missing something in Batch? I'm still a medium Batch Programmer not an expert like you and I still lack some tiny bits of knowledge in Batch
Last edited by aGerman on 26 Jun 2017 12:48, edited 1 time in total.
Reason: split from http://www.dostips.com/forum/viewtopic.php?f=3&t=7907

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Small text game

#2 Post by ShadowThief » 25 Jun 2017 03:41

Flags and switches are the same thing. It's general programming terminology, not limited to batch. You'll also see them referred to as "options." https://unix.stackexchange.com/question ... n-argument

(This is the part where somebody else jumps in and goes "Nuh-uh! Flags take options and switches don't!" to which I'll reply "oh my God, who cares?")

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Small text game

#3 Post by aGerman » 25 Jun 2017 03:58

PaperTronics wrote:What are flags?

A flag represents a boolean condition. E.g. yes or no, something is present or omitted, something is true or false, something is 1 or 0, etc. Usually program options that are not followed by a related value meet the above explanation so you may call them flags.

Code: Select all

if /i a==A ...
You may call /i a flag because its presence/absence indicates whether or not upper/lower case shall be ignored.

Code: Select all

timeout /t 10
Option /t is not a flag. It specifies that the following number is the time to wait. /t without related value will fail.

Steffen

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Small text game

#4 Post by PaperTronics » 26 Jun 2017 05:42

So flags are just the optional switches?

Although I already know about switches, options, boolean values etc. from other programming languages that I've learnt but flags were a new thing for me.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Flags in programming

#5 Post by aGerman » 26 Jun 2017 07:15

The easiest way to imagine what a flag is would be the flag on a mail box.
https://upload.wikimedia.org/wikipedia/ ... ox_USA.jpg
Flag up - mail in, flag down - no mail in. It's just a boolean as I said (because there is no such thing like flag at 1° because 1 letter is in :wink: ).

Flags are quite common in programming languages. I wonder why you didn't know them. If you have to save several flags you may use a bit field that is, an integral number where every bit is a flag with its own meaning. Bit fields are known in Batch, too. E.g. the return code of ROBOCOPY is such a bit field.

Steffen

(FWIW We are totally off-topic now in viewtopic.php?f=3&t=7907 So I split the thread ...)

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Flags in programming

#6 Post by thefeduke » 26 Jun 2017 13:51

I recently wrote elsewhere:
thefeduke wrote:You attempted to use the /M and /e tags of findstr inappropriately. On examining the output of this utility, I found the year to be at the beginning of the line. The /m tag is for a filename that you are not actually searching.
It appears that I should have said "flags" instead of "tags". I hope that I was understood, anyway.

So then, an option that requires a value is indeed called an "option" or is it a subset of options that has is own name? Does that make a "flag" a subset of "option" or its own entity alongside it, as both being different types of "arguments"?

I guess that a "tag" could, under certain circumstances, be a name for the value of an "option"

John A.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Flags in programming

#7 Post by aGerman » 26 Jun 2017 15:00

Normally a tag is an additional information (metadata) that describes something. It can be used to classify something (e.g. twitter hashtags, or tagging a question at Stack Overflow with one or more topics) in order to easier find similar/related themes that are tagged the same.
Another use for the term tag is for the markup elements in HTML or XML. E.g.
<title>My Page</title>
The title tag describes/specifies the text "My Page" to be the title of an HTML document.

So I would call the name of the option a tag rather than its value. Taking TIMEOUT as an example again, 10 is tagged by /t in order to specify it being the time to wait. But I guess that's more or less theoretical. I think tag was never commonly used in this context.

Steffen

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Flags in programming

#8 Post by PaperTronics » 26 Jun 2017 23:30

Now I get it! :wink:

Although I already know about tags as I've learnt HTML and CSS, I didn't know about flags because I only know one interpreter-based language which is Python, which I also didn't learn completely as it was getting too much boring for me. :mrgreen:
I hope to learn C++ after I've mastered or atleast know all aspects of Batch.

Post Reply