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.
 
  • Locked thread
Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
http://gamesfromwithin.com/the-const-nazi

I don't care about const tbqh :justpost:

Adbot
ADBOT LOVES YOU

Cat Face Joe
Feb 20, 2005

goth vegan crossfit mom who vapes



first view

Zlodo
Nov 25, 2006
not using const makes you a literal butt

SmokaDustbowl
Feb 12, 2001

by vyelkin
Fun Shoe
bash the fash

Doc Block
Apr 15, 2003
Fun Shoe
I don't use const, but 99% of my code is Objective-C so that's OK.

edit: I kind of think that if your functions/methods are so long that you need to declare local variables as const just to know if they've changed, then you need to either declare the local variable closer to where it's actually used, or refactor that function.

Doc Block fucked around with this message at 00:59 on May 14, 2015

Pittsburgh Fentanyl Cloud
Apr 7, 2003


I'm just a regular Nazi, OP.

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

I don't use const, but 99% of my code is Objective-C so that's OK.

edit: I kind of think that if your functions/methods are so long that you need to declare local variables as const just to know if they've changed, then you need to either declare the local variable closer to where it's actually used, or refactor that function.

same. i don't really understand the use

but Swift has let and var. who uses let? maybe there's good reasons, i dunno. haven't really got into Swift yet

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
const died to me the day I learned that it doesn't really help the compiler in any significant way

it also makes code a little annoying to read imo

Zlodo
Nov 25, 2006

Symbolic Butt posted:

const died to me the day I learned that it doesn't really help the compiler in any significant way

its about helping the programmers to not gently caress up not the compiler

"what? classes arent helping the compiler to generate better code? gently caress you i'm putting everything in global functions"

although i guess there are several degrees of fascism, i dont make locals const myself

quote:

it also makes code a little annoying to read imo

use auto all day erryday to remove useless noise which const isn't and have the pleasure of getting random coworkers asking if you are the crazy person who dared using a ~scary new c++ feature~ in the codebase

pram
Jun 10, 2001
c++ is trash city

Doc Block
Apr 15, 2003
Fun Shoe
C++ is awful, don't use it, problem solved.

sarehu
Apr 20, 2007

(call/cc call/cc)

Doc Block posted:

I don't use const, but 99% of my code is Objective-C so that's OK.

edit: I kind of think that if your functions/methods are so long that you need to declare local variables as const just to know if they've changed, then you need to either declare the local variable closer to where it's actually used, or refactor that function.

If your variable's const then a const version of the method will be called, and on types such as GNU copy-on-write std::strings that will be faster.

Also your post is a fallacy, using const increases the size you can make functions while they're still readable.

pram
Jun 10, 2001
wow nice fallacy fucktard

Doc Block
Apr 15, 2003
Fun Shoe
i mean that if a function is so long that a quick look through doesn't tell you whether or not a local variable gets changed then you need to probably refactor that function, rather than slapping const in front of the variable's declaration and calling it a day. at least rewrite so all the code that does a certain thing is all in one area of the function, so the variables used will be declared close by and you can easily see if they get changed or not.

30 TO 50 FERAL HOG
Mar 2, 2005



Doc Block posted:

i mean that if a function is so long that a quick look through doesn't tell you whether or not a local variable gets changed then you need to probably refactor that function, rather than slapping const in front of the variable's declaration and calling it a day. at least rewrite so all the code that does a certain thing is all in one area of the function, so the variables used will be declared close by and you can easily see if they get changed or not.

member variables start with m_
function variables with f_

first letter after is type

use descriptive camel case

m_bDickIsInBox

sarehu
Apr 20, 2007

(call/cc call/cc)

Doc Block posted:

i mean that if a function is so long that a quick look through doesn't tell you whether or not a local variable gets changed then you need to probably refactor that function, rather than slapping const in front of the variable's declaration and calling it a day. at least rewrite so all the code that does a certain thing is all in one area of the function, so the variables used will be declared close by and you can easily see if they get changed or not.

Somebody doesn't understand continuity arguments.

GameCube
Nov 21, 2006

No Flash? Try the QuickTime video version.

GameCube
Nov 21, 2006

I am indeed a const nazi, but most of my work is done in windows ce so my opinion is irrelevant in 2015.

Doc Block
Apr 15, 2003
Fun Shoe
I guess I don't know what a continuity argument is, unless you mean a parameter that gets passed to a function/method just so it can pass it on to something else. But that doesn't have a whole lot to do with declaring local variables as const, so v:shobon:v

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

LP0 ON FIRE posted:

same. i don't really understand the use

but Swift has let and var. who uses let? maybe there's good reasons, i dunno. haven't really got into Swift yet

use let unless you specifically need to use var

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
rust did it right. you should have to do more typing to make something non-const

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Symbolic Butt posted:

const died to me the day I learned that it doesn't really help the compiler in any significant way

it also makes code a little annoying to read imo

it can help the compiler though, example:

code:

extern NSString * const MyFooDidBarNotification;

the compiler can assume MyFooDidBarNotification never changes and doesn't need to reload it every use

BONGHITZ
Jan 1, 1970

all the old men use const

it is there for a reason

Zam Wesell
Mar 22, 2009

[Zam is suddenly shot in the neck by a toxic dart; Anakin and Obi-Wan see a "rocket-man" take off and fly away, and Zam dies]
no nazi propaganda in the 'POS

ban gas op thread

jony ive aces
Jun 14, 2012

designer of the lomarf car


Buglord

As a Millennial I posted:

No Flash? Try the QuickTime video version.
:agreed:

even for 2010 that's shameful

Sweevo
Nov 8, 2007

i sometimes throw cables away

i mean straight into the bin without spending 10+ years in the box of might-come-in-handy-someday first

im a fucking monster

const entration camp

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
const is Good and Correct and should be used everywhere. on variables, on functions. all in the aid of not violating assumptions. similarly, you should strive for idempotence in everything you do, and name the unavoidable exceptions things that make it obvious that they're exceptions

gonadic io
Feb 16, 2011

>>=
i just use languages in which the const is implicit and you need to put a 'mut' (or a new[STRef|IORef|Mvar] et al)

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

eschaton posted:

it can help the compiler though, example:

code:
extern NSString * const MyFooDidBarNotification;
the compiler can assume MyFooDidBarNotification never changes and doesn't need to reload it every use

but isn't the issue that MyFooDidBarNotification can actually change because of pointer aliasing? the way I heard about it is that the compiler has to always figure out if the variable is really constant so the const declaration end up making no difference

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Zlodo posted:

its about helping the programmers to not gently caress up not the compiler

"what? classes arent helping the compiler to generate better code? gently caress you i'm putting everything in global functions"

although i guess there are several degrees of fascism, i dont make locals const myself


use auto all day erryday to remove useless noise which const isn't and have the pleasure of getting random coworkers asking if you are the crazy person who dared using a ~scary new c++ feature~ in the codebase

dude functions are like super great

I loving love functions


anyway I use enums for global constants instead of const or #define and that's pretty much my pseudo-const correctness practice

Zlodo
Nov 25, 2006

Doc Block posted:

C++ is awful, don't use it, problem solved.

fiat dollars are awful use bitcoin instead

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
yeah i go crazy with const, that way all my spaghetti templates and poo poo get compiled into 1 liners that could have been easily represented in plain C but i really want my compile times to increase by 50 orders of magnitude

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off
lmao, templates.

Baxate
Feb 1, 2011

i sometimes call c++ c-- because its actually worse than C!!

The Management
Jan 2, 2010

sup, bitch?

Doc Block posted:

C++ is awful, don't use it, problem solved.

The Management
Jan 2, 2010

sup, bitch?
const is a contract in your function declaration.

#define LOCAL_VALUE 0x42069

Doc Block
Apr 15, 2003
Fun Shoe
Only place for const is at the top of the file:
Objective-C code:
static const int DBHowManyLicksDoesItTakeToGetToTheCenterOfATootsieRollTootsiePop = 3;
And in method declarations if the method takes something other than an Objective-C class or block.
Objective-C code:
- (void)whyIsThisMethodTakingACString:(const char *)stupid;

Doc Block fucked around with this message at 18:07 on May 14, 2015

~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD
R# tells me to make something const, I make it const

same with var

MORE CURLY FRIES
Apr 8, 2004

ES6 has const

Adbot
ADBOT LOVES YOU

MORE CURLY FRIES
Apr 8, 2004

it also has let

  • Locked thread