When you do that, reading your code is like reading Dune for the first time. I have to keep jumping back and forth to the reference to figure out what's going on.
Because it wastes memory and decreases performance, that's why.
If there's a section of code in your function that may or may not be executed, depending on a conditional, then allocating the memory for variables used within that code block will be a waste if you end up not executing it. Now, you could argue that that block should be turned into a separate function, but now you're doing another function call (unless it gets optimized out) which wastes performance, and you're making the code more cluttered if the code block is relatively small and not really worth turning into a separate function.
Are not all the local variables allocated on the stack in the function prologue anyway? no matter where in the function they are defined. A typical function starts with subtracting the stackpointer to make space for the local variables if i'm not mistaken.
C90 allows declarations (almost) anywhere; you just have to use an explicit binding construct, which in C consists of a statement block. That is, instead of this:
{
int x = 3;
do_something();
int y = 4;
}
you write this:
{
int x = 3;
do_something();
{
int y = 4;
}
}
As a Lisp programmer, I prefer clear binding constructs which put the variables in one place. The (define ...) in Scheme that you can put anywhere makes me cringe; you have to walk the code to expand that into proper lambdas before you can analyze it. Other Lisp programmers don't agree with me. The CLISP implementation of Common Lisp, whose core internals are written in C and which historically predates C90, let alone C99, uses a "declarations anywhere" style on top of ANSI C. This is achieved with a text-to-text preprocessor called "varbrace" which basically adds the above braces in all the right places.
You get better locality with explicit binding blocks, because their scope can end sooner:
{
foo *ptr = whatever();
/* this is a little capsule of code */
/* scope of ptr ends */
}
{
foo *ptr = whatever_else(); /* different ptr */
/* this is another little capsule of code */
}
These tighter scopes are much more tidy than the somewhat scatter-brained "from here to the end of the function" approach.
I can look at that capsule and know that that ptr is meaningful just within those seven lines of code. After the closing brace and before the opening one, any occurrence of the name "ptr" is irrelevant; any such occurrence refers to something else.
Brooklyn is a big place, and the person you're replying to did just say his neighborhood… probably little data available on any scale let alone the scale of one's neighborhood, aside from anecdotal.
> By early 2015, I had an overwhelming impression that Google is a much sloppier technology than I ever imagined.
After working there, I can definitely agree with this. Their engineering chops are pretty high but not only are there tons of bugs with their products (though complexity can cause that), but they also have very poor documentation for everything, so if you run into an awesome bug, your likeliness for finding an obvious solution without having to pnig the team responsible is about as reliable as a coin toss.
That's actually terrible advice, in my opinion. Raising a family is REALLY hard work that requires a lot of time and dedication out of you. It also restricts what you can and can't do; quitting jobs that you hate or moving somewhere to seize an opportunity become astronomically difficult with a family.
Families are important, but why limit your potential early?
I think the take away was to avoid optimizing 'potential' and stop focusing on anything really. He meant go do something else with your free time, like meet people and experience new things.
I worked for Two Sigma for about a year. They've been on a hiring spree for years, and I understood why: they're trying to build Amazon-level technology for just them.
Excellent company to work for; highly recommend them!
It's excellent until you realize that you're paying WAY more for every click than you would with AdWords and that their reach is only limited to Yelp and doesn't do THAT much to boost your presence. My mom was considering it for her daycare business but I argued against it for this reason and many other small businesses that have dealt with them concluded the same thing.
Word. My Qy8 IEMs from some no-name Chinese electronics company were $25 shipped and sound just as good as Jaybirds! I was shocked that they've gotten this good now.
I actually like declaring my variables at the top. To me, this seems more readable than searching for declaration statements throughout the code.
Why should I not do this?