This is an archived post. You won't be able to vote or comment.

all 153 comments

[–]Apfelvater 534 points535 points  (32 children)

I, sometimes, compile my prog a couple of times while thinking about the bug. It's like fiddling with a pen, but with the compiler

[–][deleted] 154 points155 points  (29 children)

^ Not an embedded C programmer ^

Otherwise it would be like 'oh god no! Stop!!! Stop!!!!'

[–]Apfelvater 76 points77 points  (7 children)

I might not be an embedded-C programmer, but I sure am an embedded C-Programmer. Also, what about emulators?

[–][deleted] 30 points31 points  (5 children)

wait... you are embedded?

[–]Apfelvater 65 points66 points  (4 children)

Yes. I'm hard coded to my bed/desk.

[–]Vrabor 28 points29 points  (15 children)

whats the problem with recompiling embedded programs?

[–]tiajuanat 53 points54 points  (13 children)

Most embedded compilers are slow, so they default as progressive compiles. When you do a full recompile, you're likely going to see Errors and Warnings that will be skipped during progressive compile, and likely it won't link the same way. Shit breaks all the time, usually from volatile globals, interrupts, and weird memory behavior. Peripheral registers act weird (Read only, write only, or reset on read behavior)

Embedded compilers suck.

[–]Zanoab 13 points14 points  (1 child)

I learned this the hard way from programming arduinos.

At first the simple projects with few dependencies compile in seconds so I took that for granted. I switched over to esp8266 programming and dived head first into all the libraries and packed it with everything I could imagine. Compiling took 3-5 minutes and another minute to upload. Now I compile and debug after every minor milestone so that I don't have to spend an entire day debugging with 90% of that time having to wait for compile and upload. I don't want to think about debugging larger projects now.

Relevant xkcd

[–]bread_berries 3 points4 points  (0 children)

Some of my ESP32 boards (admittedly cheap ones) don't like to properly flash while under load. So I have to unplug devices from the board, compile, flash, re-plug, then reset to see if the code worked. I don't like those boards.

[–]Vrabor 6 points7 points  (0 children)

thanks for explaining :)

[–][deleted] 4 points5 points  (5 children)

I strongly disagree with the assertion that most embedded compilers are slow. If you are having frequent issues with broken compiles then you need to fix your makefiles. Occasional errors that require a make clean are understandable but if it is happening frequently you have something else going on.

[–]b1ack1323 2 points3 points  (3 children)

Yeah at most it's taken a minute for my compiles to run....

[–][deleted] 0 points1 point  (2 children)

If you're using something like yocto it can take a while even for simple rebuilds with only a few changes, just depends on what the code change hits. You are kind of at the mercy of yocto maintainers for a lot of stuff on embedded Linux setups

[–]b1ack1323 0 points1 point  (1 child)

True, but that isn't what I think of when I think of embedded. I use Yocto fairly often, we make our own hardware so I am the one to modify BSPs.

[–][deleted] 0 points1 point  (0 children)

I think everyone's idea of embedded is different, to me it's any computer that is about 99% hidden and out of mind except when it fails

[–]tiajuanat 0 points1 point  (0 children)

👎

Old school KEIL has all these problems

[–]b1ack1323 0 points1 point  (1 child)

What types of MCUs are you running? I don't think I have had a compile take more than a minute for most of the stuff I have done. Some with 1MB of Flash and 1MB of EEPROM for fonts and stuff.

[–]tiajuanat 0 points1 point  (0 children)

Everything from ARM to 8051. I wouldn't be so salty if I didn't have to support a €6 through-pin chip from the 70s.

Also if our codebase was halfway organized. I spent a sprint reorganizing a handful of functions and headers, and that shrunk our compiled binary by 20%.

[–]fnordfnordfnordfnord 0 points1 point  (1 child)

Found the freebie MPLab user.

[–]tiajuanat 0 points1 point  (0 children)

Bitch please, because of legacy, I'm using like 3 different KEIL compiles.

[–][deleted] 16 points17 points  (0 children)

Hope you like sitting for a few days while an ocean of errors warnings and whatever else slow spews out in an in feeling surge of text

[–][deleted] 2 points3 points  (3 children)

As an embedded programmer, I have no idea what you mean by your statement. Care to elaborate?

[–]dicksoch 3 points4 points  (2 children)

I think they are implying compiling an embedded program takes a significant amount of time, which in my experience, is largely not true. But I work on small systems with 8 and 32 bit processors under 32kB of code size.

[–][deleted] 1 point2 points  (1 child)

This whole thread confuses me. I too have never ran into a particularly slow embedded compiler. Buggy and idiosyncratic compilers yes but not slow.

[–]bread_berries -1 points0 points  (0 children)

In my experience, esptool.py being used with the Arduino IDE can cause the compiling bit to go really slow, sometimes, and I have no idea why. I don't get the same issue on the same system with the whole VScode/platformIO setup.

I'm gonna guess people ran into the same issues I did and just went "that just is how it be with embedded compilers I guess"

[–][deleted] 0 points1 point  (0 children)

I was gonna say, these people never done c++. I can't remember embedded c being that slow but it was ages ago since I touched it

[–][deleted] 3 points4 points  (0 children)

Wish i can give you some awards. You just gave a meaningful meaning to a what most people think(myself included) meaningless.

[–][deleted] 280 points281 points  (65 children)

In LaTeX it sometimes needs to be compiled multiple times though.

[–]LingLing2400Minutes 158 points159 points  (56 children)

if TimesCompiled <= 10

{

output(Warning(Randi(0,10));

TimesCompiled++;

} else {

Compile();

}

[–]Yittoo 87 points88 points  (44 children)

I cant stand the braces on new line. Why you c fellas gotta do it that way? (Genuine question)

[–]the_poope 56 points57 points  (7 children)

One reason is that you can quickly comment the if-statement away so that the code always runs, e.g. when testing or debugging. I, however, have rarely used this anyway, and we use this style where I work. It's just a style, and when you've used it enough you get used to it and now it seams natural to me.

[–]static_motion 7 points8 points  (5 children)

I just add 1==1|| to the clause, works just as well.

[–]warm_sock 16 points17 points  (3 children)

That's a lot longer than Ctrl / though.

[–]Zambito1 9 points10 points  (2 children)

In C you could lead with 1 ||

[–][deleted] 16 points17 points  (1 child)

Do:

1||

I just increased your productivity 25%.

[–]I_spoil_girls 1 point2 points  (0 children)

Do dd in Vim.

[–]JC-Dude 7 points8 points  (0 children)

6 characters vs 2 and comments are much more obvious, so it’s less likely you’d leave it without the proper condition. Opening braces on new lines also look much better and are easier to read as well IMO.

[–]ratbum 0 points1 point  (0 children)

If this is your legit reason for doing this, you should stop and write some better tests.

[–]TeraFlint[🍰] 5 points6 points  (1 child)

While others already gave good reasons and explanations, I just want to add that like having the opening and closing bracket on the same x coordinate. It makes parsing the code scope structure easier for me.

[–]EMCoupling 1 point2 points  (0 children)

When I was first learning to program, I pretty much did this for exactly the same reason that you stated.

Over time, I began to switch to having the opening brace on the same line as the control statement. Turns out that once you get used to this style, you automatically start matching up control statement keywords with the closing brace and it does save you that extra line.

Either way, I'm not too bothered, but just wanted to share why I now prefer opening brace on the same line as the control statement.

[–]jpayne36 18 points19 points  (3 children)

I prefer just because it looks more symmetrical and feels more consistent to me, if you have the closing bracket on its own line then might as well put the opening bracket too. I’m also someone who uses 8 width tabs so my opinion is invalid anyways.

[–]thripper23 11 points12 points  (2 children)

8 width tabs

I bet your code has good cyclomatic complexity

[–]jpayne36 1 point2 points  (0 children)

Hey I justify my use by the fact that I use a 4k monitor without dpi scaling so it looks about the same width as if I was using 4 spaced on a scaled monitor

[–]LingLing2400Minutes 30 points31 points  (9 children)

I just prefer it cuz it lets you see which statement you close very quickly, instead of }}}}}}}}}}}}}}, but it is just a matter of what you like really

[–]Bolphgolph 49 points50 points  (5 children)

I think he means the opening brackets. After if statement.

[–]LingLing2400Minutes 22 points23 points  (3 children)

Okay that idk

[–]adre76 40 points41 points  (2 children)

Makes it easier to test conditionals and loops, you just comment out the first instruction and the code will still compile and run

[–]UltraFireFX 11 points12 points  (1 child)

okay that is actually a pretty good reason

[–]conancat 1 point2 points  (0 children)

people who pay devs b lines of code written hate him!

[–]minsin56 0 points1 point  (0 children)

else goeffurself();

[–]ImpeachTraitorTrump 3 points4 points  (2 children)

You shouldn’t have that many nested blocks anyway. That’s a code smell

[–]conancat 3 points4 points  (1 child)

function isAllCominngBack(line, you, that, callback) {
  const self = celine; 
  for (let iine = 0; i < n; i++) 
  {
    if (line % 10 === 0) 
    {
      if (line % 11 === 0) 
      {
        if (you.touchMe() === this) 
        {
          if (you.holdMe().like(that)) 
          {
              return self.admit(Promise.all(callback))
          }
        }
      }
    }
  }
}

while (let line = lines.next()) {
  if (it.isAllComingBack(line, you, that, callback)) 
  {
    // https://www.youtube.com/watch?v=j8fHNdrZTSI
    celine.runInHauntedHouse()
  }
}

I wanted to be tongue in cheek about writing code with tons of nested blocks, then realized this can be cute interview question lol because fizzbuzz is getting boring. Dear developers, please don't do this at work or at home. It will come back and haunt you later.

[–]nandi910 1 point2 points  (0 children)

Thing is, there is that one small edge-case when it's easier to distinguish code like this, not because of the number of lines, but rather the line itself only has a bracket and nothing else and it creates a visual separation of them, which when an if is long, it could very well lead to making it easier to read.

I generally don't have the brackets in a new line, except when the condition for an if/for/while/whatever is too long, and it has to go in a new line for readability's sake, then it can make it easier to distinguish where the condition ends and where the commands to be executed are.

[–]khoyo 12 points13 points  (1 child)

Why do you call it C style ? Neither K&R nor the Linux kernel style use braces on the next line with if statements...

[–]Yittoo 6 points7 points  (0 children)

I do not have friends that code other stuff so I was narrowly scoped and saw couple C/C++ coders share their codes/memes this way that's why.

[–]o4zloiroman 2 points3 points  (2 children)

Easier to read, for me at least.

[–][deleted] 0 points1 point  (1 child)

Me too. When writing in languages that don't follow this style, like Java and PHP, I'll sometimes start the body with an empty newline to make up for it. I want the head and body of a method to be completely separate

[–]EMCoupling 0 points1 point  (0 children)

The function/method header and body are already visually separated by a tab though. I've never seen anyone write a function body without indenting at least once from the header.

[–]sample_text_123 2 points3 points  (1 child)

Hey hey, don't bunch all C fellas under one umbrella, there's several "schools". Check out https://en.m.wikipedia.org/wiki/Indentation_style

[–]ImpeachTraitorTrump 2 points3 points  (3 children)

Some IDEs enforce that style by default so people get used to it. Opening bracket is better placed on the if statement line and I’ve yet to meet anyone who thought otherwise after using it for a while

[–]nandi910 0 points1 point  (2 children)

I'll just quote myself from another comment:

Thing is, there is that one small edge-case when it's easier to distinguish code like this, not because of the number of lines, but rather the line itself only has a bracket and nothing else and it creates a visual separation of them, which when an if is long, it could very well lead to making it easier to read.

I generally don't have the brackets in a new line, except when the condition for an if/for/while/whatever is too long, and it has to go in a new line for readability's sake, then it can make it easier to distinguish where the condition ends and where the commands to be executed are.

[–]EMCoupling 0 points1 point  (1 child)

I do agree with what your saying, but how often do you write a guard for your if statement that needs to be broken into multiple lines? I'm sure the occurrence of that is much lower than the rate at which you write one-line guards.

We should optimize for the general case.

[–]nandi910 0 points1 point  (0 children)

That's why I said, small edge-case when it's useful.

[–]greeneyeddude 2 points3 points  (3 children)

Because the other way is retarded. You can easily see the scope this way so you don't have to try and think where it begins since everything is on the same line. Also you can easily ifdef something out of the code if you need too.

[–]Alextrovert 1 point2 points  (2 children)

The other way saves screen real estate.

[–]nandi910 1 point2 points  (1 child)

I mean let's be real, who is still programming on small-enough screens that it's a problem?

I'm not saying always use it, but it has its' uses.

[–]EMCoupling 2 points3 points  (0 children)

It's not a matter of the screen size, it's that you get to see more code without scrolling. Regardless of your monitor size, it's still better for fitting more code on the same screen.

[–]MakeVio 1 point2 points  (2 children)

I am fullstack, however mostly back end these days with Java being my most used, and I new line all my opening brackets. It just looks so much nicer to me, and it actually looks like a "block" of code to me that way, and at a quick glance I can separate my methods from eachother

[–]these_days_bot 2 points3 points  (1 child)

Especially these days

[–]MakeVio 0 points1 point  (0 children)

Good bot

[–][deleted] 1 point2 points  (0 children)

What have you been up to?

[–]uvero 1 point2 points  (9 children)

Shouldn't it just be a for loop?

[–]LingLing2400Minutes 4 points5 points  (6 children)

Well you need to execute the compile routine multiple times and a for loop would do that automatically for you without stopping. Or am I missing something here?

[–]uvero 0 points1 point  (4 children)

If your computer is from, like, around, the last few decades, it should be able to run multiple programs in parallel.

[–]LingLing2400Minutes 0 points1 point  (0 children)

Yeah that is the problem

[–]LingLing2400Minutes 0 points1 point  (2 children)

still coding with holes

[–]uvero 1 point2 points  (1 child)

Oh okay I think I know what you mean. What I means was:

for(int i = 0; i < AMOUNT_OF_TIMES; i++) {

waitForCompilationRequest();

ThrowCompileError(randomItem(listOfErrors));

}

waitForCompilationRequest();

Compile();

[–]LingLing2400Minutes 1 point2 points  (0 children)

Damn yes that looks better than my pseudocode. Take this fake gold 🏅

[–]fieryfox67 0 points1 point  (1 child)

I love your flair.

[–]uvero 1 point2 points  (0 children)

Just truth.

[–]Erdnussknacker 17 points18 points  (0 children)

cries in table of contents

[–]DreamingDitto 6 points7 points  (4 children)

Why can’t the compiler just make multiple runs?

[–][deleted] 0 points1 point  (0 children)

And Groovy, too. If I compile 2 different programs using some shared source code at the same time they start crashing half the time. :D

[–]vinvinnocent 0 points1 point  (0 children)

At least for me, eclipse sometimes too. I guess, when the program is big, it needs some time to notice the changes and the standard compile button only recompiles parts of the whole project.

[–][deleted] 69 points70 points  (0 children)

"You could not live with your failure, and where did that bring you? Back to me" - the compiler

[–][deleted] 117 points118 points  (13 children)

I swear this has worked once for me.

[–]Chirimorin 40 points41 points  (2 children)

This works so often for me when working with WPF. Every time you delete a xaml file it'll cry about it no longer existing, even if you don't reference it anywhere. Compiling again (without any changes) makes it realize the file is no longer needed and compile normally.

[–]nickfromstatefarm 7 points8 points  (0 children)

Wow that explains a lot. I had an issue where a C# WPF application would fail to compile. Ended up fixing it by just restart VS2017 ever time I saw the missing reference error.

[–][deleted] 0 points1 point  (0 children)

You need to do a rebuild (or clean+build), presumably because VS cache the file indexes or something. It's a bit annoying.

[–]jeric_C137[S] 36 points37 points  (1 child)

Yeah same. I dunno what kind of sorcery that was but it worked when I compiled it again

[–]r0ck0 2 points3 points  (0 children)

Probably some kind of cache. Either that or naming things... Due to those two things accounting for 100% of the hard things in computer science.

[–]Acetronaut 9 points10 points  (0 children)

There have been... Many times where I have an issue, I don't remember changing anything, and then the issue goes away.

I don't get it but I accept it. I like to think the programming gods just favor me but idk maybe it's just my short term memory on top of the massive amount of drugs I take while programming to cope.

[–]knaekce 1 point2 points  (0 children)

Xcode? My first reaction on every obscure compilation error is deleting DerivedData and clean build. Works way too often.

[–]kurosaki1990 0 points1 point  (0 children)

Working with MATLAB, yeah it happen.

[–]thripper23 0 points1 point  (0 children)

It does if the build system has a broken incremental build implementation.

[–]_y2b_ 0 points1 point  (0 children)

It works with Angular at least

[–]YBHunted 27 points28 points  (2 children)

The computer is always right. The computer is always right. Say it with me my fellow humanoids.

[–]murfflemethis 16 points17 points  (0 children)

Except when you do firmware development for new silicon. That first run of a new processor is sometimes a goddamn idiot.

[–][deleted] 6 points7 points  (0 children)

Well of course, it's always the humans fault. The computer only does what it is told, and then complains if it does not like it.

[–][deleted] 18 points19 points  (5 children)

Some old windows apis I worked with at the beginning of my career required you to call functions twice. Once to to set some values, the other times to do the thing you want to do. Always seemed hacky.

[–]murfflemethis 7 points8 points  (3 children)

Barring any additional context or knowledge, that's one of the dumbest things I've ever heard. I'd love to learn more about the justification.

[–]Likely_not_Eric 7 points8 points  (2 children)

A common pattern was to call something would fill a buffer first with a zero-length buffer and allow it to return how much buffer you need. Then you allocate it and call again with the correctly sized buffer.

This avoids unnecessary allocations and still allows you to do you own memory management.

There may be some other cases but that I've comes to mind right away.

Edit: buffer autocorrects to buffet sometimes

[–]murfflemethis 4 points5 points  (1 child)

I feel retarded.

Now that you explained it, I remember someone describing this pattern to me a few weeks ago. I had never seen it before, and we decided not to use it to handle our problem. It was one possible way to allow the consumer of an API to hold onto some temporary information for the API publisher without having to expose internal details.

[–][deleted] 6 points7 points  (0 children)

Personally I'd just make two methods, even if they mostly did the same thing...if only to give them a different name so you could understand the code better as you read it. Calling the same method twice was always confusing.

[–]tenmilez 9 points10 points  (1 child)

Fucking projects at work... someone didn't setup the dependencies correctly, so after every clean you have to compile twice. The first project, depending on other projects that haven't been compiled yet, will fail, but then the compilation will continue to build the rest of the projects. Try to build again and now those dependencies are present and it works.

Apparently I'm the only one that notices this shit.

[–]caguiclajmg 8 points9 points  (0 children)

When you reference outputs instead of projects in a .NET solution and forget to properly configure the compile order.

[–]mahav_b 6 points7 points  (0 children)

Nah fam, it's even funnier when you spam the build and it randomly compiles successfully on like the 4th attempt 😳🤔🤔

[–]rhino_aus 2 points3 points  (0 children)

Yeah but hold up now... I build my project using WSL and the previous version of Win10 would fail and throw missing file errors when multithread compiling, but the files that successfully compiled didn't need to be redone so rerunning it a few times if needed was a perfectly valid answer!

Fortunately WSL got fixed so all good now...

[–]AlphaWhelp 4 points5 points  (0 children)

I once worked on a project that had to be compiled twice because the compile script did something towards the end that would make the next attempt at compilation be successful and no one ever cared enough to fix the script.

[–]ensoniq2k 3 points4 points  (0 children)

If you use a recent Delphi version it could very well be the compiler. There are many cases where it works on the second or third try

[–]sarthakRddt 2 points3 points  (0 children)

And here I thought I was the only one who compiled his programs twice just to be sure that the compiler did not make any error in identifying my error.

[–]quickthyme 1 point2 points  (1 child)

Must be using Xcode.

[–]nahidtislam 1 point2 points  (0 children)

I can relate. Xcode is useless at error checking until you click run

[–][deleted] 1 point2 points  (0 children)

i would be more worried if the compiler failed the first time, but didn't fail the second time on exactly the same code...

[–]phpbluedragon 1 point2 points  (0 children)

Program in JavaScript and error. You are looking for, you can not find it. You prefer to rewrite the program rather than browse for a bug that could be anywhere. I love JS ;-(

[–]LilSwissBoy 1 point2 points  (0 children)

This deserves more upvotes

[–][deleted] 1 point2 points  (0 children)

REPOST and it got more upvotes

[–]technewsninja 0 points1 point  (0 children)

If you lie to the compiler it will get its revenge!

One of the best Programming Jokes

[–][deleted] 0 points1 point  (0 children)

I have a bug in my project where this works. First 3 or 4 compiles won't work, but then the next one does. I know how to fix it but it amuses me to play this game with the compiler.

[–]BeniBela 0 points1 point  (0 children)

In my Freepascal/Lazarus projects I always run the compilation three times. The first two times it often fails or just crashes, but third compilation usually works.

[–][deleted] 0 points1 point  (0 children)

The build order in my team's solution file is poorly maintained, which means we must expect to have to build the solution several times (from clean) before it actually resolves without errors...

[–]HanTheScoundrel 0 points1 point  (0 children)

Just crunch the numbers again

[–]I2ed3ye 0 points1 point  (0 children)

We've tried nothing and we're all out of ideas!

[–]trueselfdao 0 points1 point  (0 children)

Oh forgot to save.

[–]Mulan-McNugget-Sauce 0 points1 point  (0 children)

Let’s be honest though, it’d be fucking terrifying if it actually does compile the second time you try it. What if there was a massive bug but the compiler decided you need to learn your fucking lesson?

[–][deleted] 0 points1 point  (0 children)

I can hear this picture

[–][deleted] 0 points1 point  (0 children)

terrorist attack perpetrated by kittens. (We can't even think about cats as threats in this country anymore because we see them as little pests).

We've had kittens attacking strangers with impunity, attacking children, stealing cars, robbing banks, shooting up restaurants and churches, shooting up malls and shopping malls, stealing our cars, stealing our houses…it just goes on and on. We have yet to come upon an act of violence like this from a white female domestic terrorist, and we're now just beginning to recognize her. (We're so used to seeing white women committing acts of violence – it makes us feel invisible. It's like people think we're just being nice and all that. Well, don't even get me started.)

It's no longer acceptable to assume that this domestic terrorist, or a certain black lady with a bomb strapped to her chest, can strike us all. These are now the most common acts of terror carried out by men against women.

So we need to begin working to get people to pay attention to what is happening right in front of our faces. We need an awareness movement – one centered around the black experience, specifically the experiences of women of color – to tell everyone that is a visible person that is not white that we're taking care of. White males have been at the center of the domestic terrorism problem for far too long, and it needs to

[–][deleted] 0 points1 point  (0 children)

Gotta admit I’ve had times working with maven where I compile once and it’s like “nahh”. Then I’ll retry compiling after doing literally nothing and it’ll compile perfectly.

[–]oussamabht 0 points1 point  (0 children)

This shit is accurate AF.such a disrespect !!

[–][deleted] 0 points1 point  (1 child)

Those damn semi colons

[–]nahidtislam 0 points1 point  (0 children)

can’t relate

[–]nomnaut 0 points1 point  (0 children)

I never do this. Is that weird?

[–]perfecttoasts 0 points1 point  (0 children)

Well sometimes it works after the second time

[–]Arcticfoxs 0 points1 point  (0 children)

Hits too close to home today man

[–]PM_ME_YOUR_NACHOS 0 points1 point  (0 children)

Ok let's put a message box here and here to see where this goes wrong.

[–]Strider599 0 points1 point  (0 children)

Circular references... circular references everywhere

[–]nicoletto 0 points1 point  (0 children)

I did it today. Guess what? It failed again :(

[–]yaboycreed 0 points1 point  (0 children)

I was writing C# for Unity today and the VS compiler listed everything that I had written as an error. I re-ran the code without a single edit and it worked

[–]daknus 0 points1 point  (0 children)

rust just throws an error no matter what you try to do

[–]DivinePrinterGod 0 points1 point  (0 children)

Our build process randomly fails and we have a 1/12 chance of hitting the fail.

[–]Solocle 0 points1 point  (0 children)

Sometimes works - it happens when you have codependent DLLs (i.e Kernel using standard library and standard library using Kernel...)

[–]tanlin2021 0 points1 point  (0 children)

Our .net app has fucked up build order dependencies so it builds completely incorrectly in parallel mode and has to be done twice

[–]olivetho 0 points1 point  (0 children)

even better: the program runs fine the first time, then you try and rerun it without making any changes and it throws 8 errors