In brainfuck, how does the interpreter deal with going below 0 in the tape? - brainfuck

I am not sure that I understand what exactly the interpreter does to handle moving the current index of the tape below zero. Should the interpreter allow the tape to go below 0? Thank you!

That is simply undefined behavior. Some allow it, although most don't, because it's simpler to implement that way.

You will need to provide a set of options for a programmer on strategy how to handle out-of-range cases. See my Brainfuck engine and how I resolved this issue.Brainfuck Runner

Related

Reason behind implicit returns usage in Swift

Do you know what is the rationale behind usage of implicit returns in single-expression closures in Swift?
Is it just a way to make code cleaner and neater or is there any hidden performance gain associated with that?
Thanks,
Piotr
It's only to look cleaner. There is no hidden performance gain, and even if there was, it would be so small nothing could track it. The only reason for it is to be cleaner and neater, as Swift is that. The rationale is that it will be easier to read.

Why would you NOT want the compiler to optimize your code?

Once I realized there is the option for this in GCC, I asked google and plenty of people want to know how to tell the compiler not to optimize the code. This seems counter-productive, what purpose can this serve to help the programmer? Debugging perhaps? How would it help in a situation where it is preferred to do this?
You said it - debugging. The optimizer can restructure code so that functions no longer exist and statements are intermingled. Turning off optimization is often necessary to allow a debugger to map machine/byte code addresses back to a source location.
As Tikhon mentions, it can also be useful if the optimizer has a bug.
The main reason is compile time: turning on optimizations can significantly increase build times without necessarily giving much benefit.
Also, certain optimizations can affect the accuracy and correctness of your program. However, these optimizations usually need to be turned on explicitly rather than with a flag like -O2.
Some optimizations--things like inlining--can increase the size of the executable. In certain cases, this is an important consideration.
Optimization can also have negative effects on your code. For example, speed might increase but at the expense of using more memory. This is not always desirable.

What can use to avoid the msgSend function overhead?(Obj-c)

Hello everyone help me please!!!!
What can use to avoid the msgSend function overhead?
maybe answer is IMP, but I not sure.
You could simply inline the function to avoid any function call overhead. Then it would be faster than even a C function! But before you start down this path - are you certain this level of optimisation is warranted? You are more likely to get a better payoff by optimizing the algorithm.
The use of IMP is very rarely required. The method dispatching in Objective-C (especially in the 64-bit runtime) has been very heavily optimised, and exploits many tricks for speed.
What profiling have you done that tells you that method dispatching is the cause of your performance issue? I suggest first you examine the algorithm to see first of all where the most expensive operations are, and see if there is a more efficient way to implement it.
To answer your question, a quick search finds some directly relevant questions similar to yours right here on SO, with some great and detailed answers:
Objective-C optimization
Objective-C and use of SEL/IMP

Why use MEMCACHED_BEHAVIOR_NOREPLY?

I am writing a library that wraps libmemcached.
I noticed that there is an interesting behaviour setting for memcached which says that I can indicate that I do not care about the results of my memcached commands...
It is known as MEMCACHED_BEHAVIOR_NOREPLY. Why would somebody want to use this?
It would be great if someone could point out a few use cases? multi-get / multi-set spring to mind, but I am not clear how this would be useful.
ASCII protocol noreply was a mistake. Don't use it.
Binary protocol noreply can be used to make really awesome optimizations without any loss of correctness.

How do you define 'unwanted code'?

How would you define "unwanted code"?
Edit:
IMHO, Any code member with 0 active calling members (checked recursively) is unwanted code. (functions, methods, properties, variables are members)
Here's my definition of unwanted code:
A code that does not execute is a dead weight. (Unless it's a [malicious] payload for your actual code, but that's another story :-))
A code that repeats multiple times is increasing the cost of the product.
A code that cannot be regression tested is increasing the cost of the product as well.
You can either remove such code or refactor it, but you don't want to keep it as it is around.
0 active calls and no possibility of use in near future. And I prefer to never comment out anything in case I need for it later since I use SVN (source control).
Like you said in the other thread, code that is not used anywhere at all is pretty much unwanted. As for how to find it I'd suggest FindBugs or CheckStyle if you were using Java, for example, since these tools check to see if a function is used anywhere and marks it as non-used if it isn't. Very nice for getting rid of unnecessary weight.
Well after shortly thinking about it I came up with these three points:
it can be code that should be refactored
it can be code that is not called any more (leftovers from earlier versions)
it can be code that does not apply to your style-guide and way-of-coding
I bet there is a lot more but, that's how I'd define unwanted code.
In java i'd mark the method or class with #Deprecated.
Any PRIVATE code member with no active calling members (checked recursively). Otherwise you do not know if your code is not used out of your scope analysis.
Some things are already posted but here's another:
Functions that almost do the same thing. (only a small variable change and therefore the whole functions is copy pasted and that variable is changed)
Usually I tell my compiler to be as annoyingly noisy as possible, that picks 60% of stuff that I need to examine. Unused functions that are months old (after checking with the VCS) usually get ousted, unless their author tells me when they'll actually be used. Stuff missing prototypes is also instantly suspect.
I think trying to implement automated house cleaning is like trying to make a USB device that guarantees that you 'safely' play Russian Roulette.
The hardest part to check are components added to the build system, few people notice those and unused kludges are left to gather moss.
Beyond that, I typically WANT the code, I just want its author to refactor it a bit and make their style the same as the rest of the project.
Another helpful tool is doxygen, which does help you (visually) see relations in the source tree.. however, if its set at not extracting static symbols / objects, its not going to be very thorough.