Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Boiled Water posted:

don't be daft

javascript sucks rear end but implicit semicolon insertion is the least of it

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Private Speech posted:

how do people feel about #pragma once?

there's this GCC dev laying out a decent case for why it's bad

on a personal level I don't use it for more complex projects, and both cppcoreguidelines and Google C++ guidelines don't recommend it either, with broadly the same reasoning

stackoverflow and reddit have a lot of people agitating hard for it though

It's supported in the environments I write C, and harder to screw up than standards compliant defines, so I use it and it's good.

My projects usually aren't complicated.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Private Speech posted:

how do people feel about #pragma once?

there's this GCC dev laying out a decent case for why it's bad

on a personal level I don't use it for more complex projects, and both cppcoreguidelines and Google C++ guidelines don't recommend it either, with broadly the same reasoning

stackoverflow and reddit have a lot of people agitating hard for it though

I totally buy that it's incredibly difficult, and probably impossible, to implement #pragma once perfectly. as someone not implementing a c compiler, I'm not sure I care. though now I'm trying to come up with an example I'm remotely likely to run into that doesn't result in a compile or link error

also wouldn't have a problem switching to include guards or whatever. seems weird to stan for the specific spelling of #pragma once

urea
Aug 18, 2013

it's C, just say the complicated edge cases are undefined behavior and let the user deal with the fallout.

Clockwerk
Apr 6, 2005


Blinkz0rz posted:

javascript sucks rear end but implicit semicolon insertion is the least of it

agreeing with both parts of this statement

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


quote:

#pragma once has no such safety net -- if the compiler is wrong about the identity of a header file, either way, the program will fail to compile. If you hit this bug, your only options are to stop using #pragma once, or to rename one of the headers.

so, am I reading this right:

- #pragma once has bugs
- in the event you hit such a bug, your code won't compile and you will be forced to remove #pragma once
- therefore, you should remove #pragma once

?

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


NihilCredo posted:

so, am I reading this right:

- #pragma once has bugs
- in the event you hit such a bug, your code won't compile and you will be forced to remove #pragma once
- therefore, you should remove #pragma once

?

well in that case you have to mix include guards and pragma once, or forego them for the file, so I guess the argument is you might as well use include guards in the first place

of course if your include guard is just the filename then it's the same thing and not any easier to fix (in a systematic way that is)

there's also the support argument but that seems to be near universal these days

e:
here's what cppcoreguidelines says on the topic:

quote:

Some implementations offer vendor extensions like #pragma once as alternative to include guards. It is not standard and it is not portable. It injects the hosting machine's filesystem semantics into your program, in addition to locking you down to a vendor. Our recommendation is to write in ISO C++: See rule P.2.

but then cppcoreguidelines are edited by the same people as the C++ standard so

Private Speech fucked around with this message at 17:03 on Jul 31, 2020

The_Franz
Aug 8, 2003

Private Speech posted:

how do people feel about #pragma once?

there's this GCC dev laying out a decent case for why it's bad

on a personal level I don't use it for more complex projects, and both cppcoreguidelines and Google C++ guidelines don't recommend it either, with broadly the same reasoning

stackoverflow and reddit have a lot of people agitating hard for it though

it's still technically non-standard, although i've used it since forever and never had an issue with it and it's supported everywhere unless you are using something very old or obscure. the identical filename issue is resolved by resolving absolute paths for everything and using that as your identifier. i have had issues with #ifdef guards where a project might contain, say, it's own FOO_H guard which collides with a library header that also defines it's own FOO_H guard

there were performance concerns with #pragma once a long time ago, although i would imagine that it's been addressed. in theory it should be faster since the compiler doesn't have to actually open and parse the header file before knowing if it should be ignored

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


someone on the stackoverflow thread ran a test and it's indeed slightly faster these days, though it's on the order of seconds for something with thousands of files

yippee cahier
Mar 28, 2005

I use it, my coworkers use include guards and mix and match any number of leading or trailing underscores around the uppercase filename. Sometimes with a _H even though the header is .hpp, sometimes they don’t get the filename right.

We’re going to have a CONFIG_H collision before any other scenario that breaks #pragma once.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



quote:

(The short version of why this is unfixable is that neither the Unix nor the Windows filesystem API offer any mechanism that guarantees to tell you whether two absolute pathnames refer to the same file. If you are under the impression that inode numbers can be used for that, sorry, you're wrong.)

am i reading this wrong or will you only hit this bug if you have hard-/softlinked .h files in your include path that refer to the same actual file? that seems like user error to me

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
imo the situations where pragma once doesn't work are all things you shouldn't be doing anyway and if you ever manage to hit them (approximately zero percent of people will) then the fact that it forces you to unfuck your header inclusions is a feature

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
is it really only filesystem fuckery that does it?

i cant imagine actually hitting that manually unless you have some CI setup that does it, but even then your header should only be in 1 location.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
also if you're doing that you deserve to have your builds hosed up

fritz
Jul 26, 2003

CRIP EATIN BREAD posted:

also if you're doing that you deserve to have your builds hosed up

Progressive JPEG
Feb 19, 2003

CRIP EATIN BREAD posted:

also if you're doing that you deserve to have your builds hosed up

i'd even extend that to "if the filesystem is in a weird state i want the build to fail rather than pretending it's ok"

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



error: your headers are all hosed up and your file system is poo poo

Sapozhnik
Jan 2, 2005

Nap Ghost

quote:

(Historical note: The only reason I didn't rip #pragma once and #import out of GCC when I had the authority to do so, ~12 years ago, was Apple's system headers relying on them. In retrospect, that shouldn't have stopped me.)

of COURSE this was written by some breathtakingly arrogant Apple fuckstain, how am I not surprised

"I would have unilaterally imposed my own opinions onto a very widely used piece of software, drat the consequences, were it not for the fact that Daddy would have been inconvenienced"

Apple delenda est

Xarn
Jun 26, 2015
If your compiler doesn't special case classic include guards to behave like pragma once (that is, don't open the file), you need a better compiler.

If your build runs into pragma once bugs, you either need a better platform (sorry Bloomberg guys), or stop doing stupid poo poo with your file system.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Sapozhnik posted:

of COURSE this was written by some breathtakingly arrogant Apple fuckstain, how am I not surprised

"I would have unilaterally imposed my own opinions onto a very widely used piece of software, drat the consequences, were it not for the fact that Daddy would have been inconvenienced"

Apple delenda est

uh, you read that incorrectly. he didn't rip out pragma once specifically because he didn't work for apple and so was unable to fix their system headers to not need it

Sapozhnik
Jan 2, 2005

Nap Ghost
Indeed I did, fair enough

Doom Mathematic
Sep 2, 2008

echinopsis posted:

code:
Another example based on rule 4:

(() => {
  return
  {
    color: 'white'
  }
})()
You’d expect the return value of this immediately-invoked function to be an object that contains the color property, but it’s not.
Instead, it’s undefined, because JavaScript inserts a semicolon after return.

Instead you should put the opening bracket right after return:

(() => {
  return {
    color: 'white'
  }
})()
is this true? how is this tolerated

Use a linter. It will protect you from this and many other things.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



my favorite js linter is rm -rf *

echinopsis
Apr 13, 2004

by Fluffdaddy

Doom Mathematic posted:

Use a linter. It will protect you from this and many other things.

is that something that makes it colourful

redleader
Aug 18, 2005

Engage according to operational parameters

jesus WEP posted:

get used to putting a semicolon at the end of each statement, it’s good practice for if you migrate to an actually useable language

someone set up the linter to make it an error to use a semicolon in js where not absolutely required and i don't think i've ever been so mad about a formatting decision

Sapozhnik
Jan 2, 2005

Nap Ghost
Yeah unfortunately you have to pile a whole bunch of poo poo on top of JavaScript to make it even slightly bearable to work with. At an absolute bare minimum:

Install and use Visual Studio Code (a text editor)
Install nodejs so that you can use npm so that you can install stuff
Install eslint into your project directory using npm
Install the eslint plugin for vscode.

VSCode will now yell at you if you do something dumb in JavaScript. Since JavaScript is extremely bad it is surprisingly easy to do something dumb in JavaScript.

I would strongly recommend that you also install Prettier (using npm) and its associated vscode plugin, then configure vscode to automatically reformat your code every time you save. Doesn't seem like such a big deal but having continuous auto-formatting frees up your mind from having to do a whole lot of tedious formatting poo poo work.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



echinopsis posted:

is that something that makes it colourful

thats syntax highlighting

a linter does code cleanup stuff. it might catch some errors & alert you to potential problems, but mostly its just to make your code look nice according to whatever standard you choose to configure it to

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



also, for syntax highlighting, you should use a dark theme for maximum hackitude

redleader
Aug 18, 2005

Engage according to operational parameters
use webpack op

Soricidus
Oct 21, 2010
freedom-hating statist shill

Xarn posted:

If your compiler doesn't special case classic include guards to behave like pragma once (that is, don't open the file), you need a better compiler.

If your build runs into pragma once bugs, you either need a better platform (sorry Bloomberg guys), or stop doing stupid poo poo with your file system.

if you need to use special incantations to stop everything breaking due to a file being processed more than once, you need a better language :colbert:

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Carthag Tuek posted:

my favorite js linter is rm -rf *

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Soricidus posted:

if you need to use special incantations to stop everything breaking due to a file being processed more than once, you need a better language :colbert:

but how will i win the trivia wars

cool av
Mar 2, 2013

Sapozhnik posted:

of COURSE this was written by some breathtakingly arrogant Apple fuckstain, how am I not surprised

"I would have unilaterally imposed my own opinions onto a very widely used piece of software, drat the consequences, were it not for the fact that Daddy would have been inconvenienced"

Apple delenda est

are you sure he was from apple, it sounded to me like he just didn't want to break compatibility for a major player

but lol breaking compatibility sure as hell wouldn't ever stop apple from anything ever


are c++ modules going to make this stupid problem go away?

Bloody
Mar 3, 2013

what is the point of d. it seems like at best a somewhat less warty c++?

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
there is a brutal need for a less warty cpp

d guy failed but it was worth a try. prolly rust peeps will make a solid dent

Shaggar
Apr 26, 2006

Carthag Tuek posted:

my favorite js linter is rm -rf *

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Bloody posted:

what is the point of d. it seems like at best a somewhat less warty c++?

sometimes the only way to learn is to fail. someone will take d (heh) and learn from the mistakes.

Beamed
Nov 26, 2010

Then you have a responsibility that no man has ever faced. You have your fear which could become reality, and you have Godzilla, which is reality.


Bloody posted:

what is the point of d. it seems like at best a somewhat less warty c++?

that was the point. it came out close to 20 years ago now, and it just never took off.

e: it also made some mistakes too, but it was an iterative improvement to learn from

redleader
Aug 18, 2005

Engage according to operational parameters
c/c++ includes are some real plang poo poo

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
d’s point has always been that Walter bright had enough money to retire but he enjoyed his job enough that he kept doing it for fun

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply