Quick vocab definition (Objective-C) - objective-c

I reread the explanation a couple of times, but I still don't understand what these are. Can someone explain to me what an argument and a format string are?

I'll answer before this question gets closed or downvoted too severely for not being specific or having much detail:
Format strings are used for passing 1-or-more arguments to compose a NSString object.
Check out this useful Apple documentation on String format specifiers.
Arguments are the parameters passed into a method or function.
And if you are talking about some compiler errors, such as the "format not a string literal and no format arguments" error you might see when trying to log stuff via NSLog, check out the answers to this very related question.

An argument is a variable value that you pass to something else, generally a method. In plain English, if you were to say "go run around the block 30 times", 30 would be the argument. Depending on your method, maybe "block" and "run" would be arguments as well, where you could also say "go walk around the house 10 times".
A format string is a string that describes how to format a series of arguments. These generally take the form of a string that has certain placeholders in it where the arguments will be shown in the result.

Related

Dollar and exclamation mark (bang) symbols in VTL

I've recently encountered these two variables in some Velocity code:
$!variable1
!$variable2
I was surprised by the similarity of these so I became suspicious about the correctness of the code and become interested in finding the difference between two.
Is it possible that velocity allows any order of these two symbols or do they have different purpose? Do you know the answer?
#Jr. Here is the guide I followed when doing VM R&D: http://velocity.apache.org/engine/1.7/user-guide.html
Velocity uses the !$ and $! annotations for different things. If you use !$ it will basically be the same as a normal "!" operator, but the $! is used as a basic check to see if the variable is blank and if so it prints it out as an empty string. If your variable is empty or null and you don't use the $! annotation it will print the actual variable name as a string.
I googled and stackoverflowed a lot before I finally found the answer at people.apache.org.
According to that:
It is very easy to confuse the quiet reference notation with the
boolean not-Operator. Using the not-Operator, you use !${foo}, while
the quiet reference notation is $!{foo}. And yes, you will end up
sometimes with !$!{foo}...
Easy after all, shame it didn't struck me immediately. Hope this helps someone.

printf: supplying variables without formatting

Is it legal to use variables in printf without supplying the formatting (such as %d, %f).
for example:
printf("value is ok\r\n",myvalue);
The command compiles without errors nor warning, though I am not absolutely sure if it is legal or dangerous.
This reference says
There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.
Base on this information, your statement is perfectly legal, however I don't thinks that this is a good idea, since you code could quickly become confusing, which might lead to bugs.
Edit: The original source does not explicitly mention the case of zero arguments. To add another source, the linux man pages states
The format string is composed of zero or more directives.
This source does not discuss what happens with additional arguments. However, combining these two sources gives a definitive answer.

Mid() don't extract string in accurate position

I am using VBA in Ms Access environment, to handle long string (memo field storing HTML originally).
After positioning by Instr(), I put the position into Mid(vStr,vStartPos,vEndPos-vStartPos+1) to extract the string, but the output doesn't match. I have already carefully checked this in immediate windows, as well as NotePad++. What I can say is Instr() and NotePad++ have given the same counting result, while Mid() is different. Mid()'s result are former than Instr()'s in some cases, and latter in other cases. I don't know the reason, and can just believe Mid() use different mechanism or have defeative (surprised!) in handling long string mixed with single-byte and bi-byte chars (but this is common in the world, and meet no problem before), and possibly some special characters.
I believe I need to custom-make a Mid() function. Any idea how to do it effectively and efficiently?
Thanks all for your reply. After I created a custom Mid() by RegEx and find that the problem has no change, I have found out the silly mistake I made. The Instr() and Mid() have no problem, but the string has been carelessly modified between them. So this case should be closed now.

Why programming documentation has square brackets and commas in weird places?

Why in various programming documentation for functions do they have square brackets around parameters, but they are ordered such that the later parameters seem to be subsets of the first? Or if the brackets in that language delineate arrays it's as if the second parameter is supposed to be inside of the array of the first, but often the parameters are not even supposed to be arrays, and also they have commas in weird places.
I've seen this style all over the place and tried to find some place where it is written down why they do this. Maybe someone just arbitrarily decided on that and other programmers thought, "oh that looks cool, I'll try that in writing my own documentation.."
Or maybe there is some big book of rules for how to make programming docs? If so I'd like to know about it.
Here is an example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
if you go to the link in the blue box near the top of the page right bellow the h2? heading "syntax" it says this: arr.slice([begin[, end]]) meaning that the first parameter is begin, and the next parameter is end, for the slice method. When you first see something like this it looks like the brackets and commas are randomly placed.. but they do it all over the place and the same way. There must be some method to the madness!
Brackets around a parameter name indicate that it is an optional parameter. E.g. you can call the slice method without an end parameter. This is just a general rule of language syntax documentation, square brackets indicate optional words/tokens.

Why do I use "parse"

What is the reasoning for parsing an integer? For instance, Integer.Parse('variable'.text)
I see this a lot and while manipulating data for a calculator I am building I found that Val('variable'.text) was all I need to use "numeric" values.
So, my question is how does Integer.Parse() help me with regards to calculators?
Thanks!
I found that "Val('variable'.text)" was all I need
If that's the case then go ahead and use Val(). But be aware that it behaves differently than .Parse() (or, often preferably, .TryParse()) methods.
For example, what do you want to do if the user inputs "123 isn't 456"? Val() will (I think) return:
123 As Double
Or how about the input "123 456"? That would be:
123456 As Double
Do you want it to be a Double? Do you want it to throw an error because it's not purely numeric? Something else? The behavior you want should be reflected in the code you write. Use Val() for one set of behaviors, .Parse() for another.