Hacker News new | past | comments | ask | show | jobs | submit | mrcrassic's comments login

> C99 allows variable declarations anywhere

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?


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.


At least I can clearly see which variables are already set, so that I don't redeclare them.


I would like to read more code that was lied out as a piece of literature: first and foremost - introduce the characters of the play!


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.


> allocating the memory for variables

Allocation of N variables on the stack is O(1) since it just moves the stack pointer by the total size of all variables.


You wrongly assume here that your C code will have to run on a stack machine.


Do you have a counterexample?


locality.

It makes the code more readable.


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.


Do you have data to support this? I too live in Brooklyn and have found the opposite to be true.


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.


this is amazing.


Sounds like Morgan Stanley


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 is also a very good way to stagnate under fear of trying something new


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.


yup, same here. I help SMBs with marketing, and Yelp is usually never worth paying for.

The only small case is when the ROI on adwords is reaching the level of diminishing returns


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.


Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: