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
Bloody
Mar 3, 2013

Volte posted:

throw it on the pile with "never use goto under any circumstances", "only return from a single point", "if (0 == var)" and other such pointless dogmas

wish I could goto a reti that early exits your posts

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer
also goddamn putting the constant before the variable in a comparison is disgusting

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

fleshweasel posted:

single return is nice, but I prefer multiple return statements without mutation to declaring a result variable at the top and mutating it in various places in the body of a function before returning it.

agreed, fleshweasel

raminasi
Jan 25, 2005

a last drink with no ice

Bloody posted:

if the type of the rhs is not obvious from looking at the expression you got bigger problems

and in this case using var is specifically discouraged

pepito sanchez
Apr 3, 2004
I'm not mexican
"strong typing is stupid and pointless" - good programmer

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

AWWNAW posted:

no it's the new PHP

haha gross

Bloody
Mar 3, 2013

pepito sanchez posted:

"strong typing is stupid and pointless" - good programmer

uhh what do you think strong typing is

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

strong typing is when you explicitly write out the full type of everything at least twice, like this:
code:
let x: std::string::String = std::string::String::new("welp,");

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
no it isn't

wait you're taking the piss nm

Soricidus
Oct 21, 2010
freedom-hating statist shill
strong typing is when you prove your superiority as a coder by wrestling the compiler into submission

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Soricidus posted:

strong typing is when you prove your superiority as a coder by wrestling the compiler into submission

what's casting in this metaphor, the safe word?

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

Blotto Skorzany posted:

what's casting in this metaphor, the safe word?

getting into a north south and jamming your balls into the compiler's eyes

pepito sanchez
Apr 3, 2004
I'm not mexican

Bloody posted:

uhh what do you think strong typing is

maybe i didn't get the point you were trying to make with "if the type of the rhs is not obvious from looking at the expression..." but yeah sometimes it's not because c# and anonymous type returns, and that's when you definitely use var. i was trying to be funny and failed.

stop making fun of me, for i am a strong typer :colbert:

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
strong typing is pressing your keyboard keys super hard

Bloody
Mar 3, 2013

hackbunny posted:

strong typing is pressing your keyboard keys super hard

it's me!

gonadic io
Feb 16, 2011

>>=

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

fart simpson posted:

strong typing is when you explicitly write out the full type of everything at least twice, like this:
code:
let x: std::string::String = std::string::String::new("welp,");

no that's just called lots of typing

FamDav
Mar 29, 2008

rjmccall posted:

reference-initialization can bind to objects of subclasses, but assignment is resolved statically

basically, if you're going to work with references, you have to understand the difference between initialization and assignment, because they are radically different

is there a compiler setting in gcc or clang that will warn if you try to assign a subclass to a reference?

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

FamDav posted:

is there a compiler setting in gcc or clang that will warn if you try to assign a subclass to a reference?
Assuming you mean "initialize a reference with an object whose type is a subclass of the referenced type," no, for the same reason there's no warning if you try to upcast a pointer. It's a safe and normal thing to do.

FamDav
Mar 29, 2008

Ralith posted:

Assuming you mean "initialize a reference with an object whose type is a subclass of the referenced type," no, for the same reason there's no warning if you try to upcast a pointer. It's a safe and normal thing to do.

no, i mean assignment

why would i mean initialization

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

FamDav posted:

no, i mean assignment

why would i mean initialization

what you do in your own ide in private is your own business, were not here to judge

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

FamDav posted:

no, i mean assignment

why would i mean initialization
because if you meant assignment then that's a perfectly normal operator= invocation on the referenced object and whatever value you're assigning, and whether the lhs is a reference or an object isn't really relevant?

Lime
Jul 20, 2004

i don't know about warning flags but i would guess they don't exist since you can acutally write assignment operators safely for polymorphic types, basically just make operator= virtual in the base class then in each derived class's override try to dynamic_cast the Base& to a Derived&

otherwise the advice is generally to disable assignment operators in polymorphic types and make some kind of virtual clone() member that returns pointers so no one can possibly get confused

but as long as you think of a = b as really a.operator=(b) for class types, i don't think all this is really confusing. assignment is always resolved statically for the right hand side (and potentially for the left hand side if not virtual) but this is just like every other member function because c++ like most oop languages only has single dispatch. it's a fundamental limitation to c++ polymorphism and something you can't really not be aware of, so assignment working like this ought to feel basically natural and expected

Lime fucked around with this message at 00:57 on Sep 7, 2015

FamDav
Mar 29, 2008

Ralith posted:

because if you meant assignment then that's a perfectly normal operator= invocation on the referenced object and whatever value you're assigning, and whether the lhs is a reference or an object isn't really relevant?

simliar to how the lhs being an object vs a reference isn't relevant to any other method call

Lime posted:

i don't know about warning flags but i would guess they don't exist since you can acutally write assignment operators safely for polymorphic types, basically just make operator= virtual in the base class then in each derived class's override try to dynamic_cast the Base& to a Derived&

otherwise the advice is generally to disable assignment operators in polymorphic types and make some kind of virtual clone() member that returns pointers so no one can possibly get confused

but as long as you think of a = b as really a.operator=(b) for class types, i don't think all this is really confusing. assignment is always resolved statically for the right hand side (and potentially for the left hand side if not virtual) but this is just like every other member function because c++ like most oop languages only has single dispatch. it's a fundamental limitation to c++ polymorphism and something you can't really not be aware of, so assignment working like this ought to feel basically natural and expected

thats fair, though i feel you could have a warning similar to the non-virtual destructor warning when an assignment occurs and there isn't a non-virtual operator=

FamDav fucked around with this message at 02:00 on Sep 7, 2015

sarehu
Apr 20, 2007

(call/cc call/cc)
Is there anything wrong with putting characters like "[" or worse, " ", in an object file symbol name?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
there are some elf toolchains that explode on symbols that aren't alphanumeric, i don't remember the details

mach-o does just fine, it is one of the few ways that mach-o is arguably superior. objc uses symbols like that all the time, including spaces

sarehu
Apr 20, 2007

(call/cc call/cc)
Well, using "gcc" to link and gdb to debug the executable on Linux, I haven't had any problems with any of "[],@# " so far.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
i was one of those devs that tried to come up with definitive rules on when to use var when it first came out and over time started typing it out of laziness and now i use it literally everywhere the compiler lets me and have never, in years of c# development, ever been confused at what the rhs is doing in a var statement.

it's one of those things where if you ask people they all have a strong opinion and yet in practice it doesn't matter at all.

Cybernetic Vermin
Apr 18, 2005

you should all write in haskell, where the type remains non-obvious when presented with not only the rhs, but the type itself

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
Sometimes in Haskell the type is clearer if you don't write it. This happens mainly when there's ridiculously generic things going on which have some fairly mundane cases. You see a lot of it in the lens library.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Cybernetic Vermin posted:

you should all write in haskell, where the type remains non-obvious when presented with not only the rhs, but the type itself

i didnt understand Arrows at all until i figured out that the a in "Arrow a" was actually of type "* -> * -> *"

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

imagine reading this with no prior knowledge and then using it in a real program, lol:

http://hackage.haskell.org/package/base-4.6.0.1/docs/Control-Arrow.html

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

i like that literally the entire documentation for the type Kleisli m a b is "Kleisli arrows of a monad." and "Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class."

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

fart simpson posted:

i like that literally the entire documentation for the type Kleisli m a b is "Kleisli arrows of a monad." and "Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class."

Bad Sneakers
Sep 4, 2004

me irl
can someone explain to me what the with\as statement in python is used for?

disclaimer: i have had exactly one semester of python

multigl
Nov 22, 2005

"Who's cool and has two thumbs? This guy!"

Bad Sneakers posted:

can someone explain to me what the with\as statement in python is used for?

disclaimer: i have had exactly one semester of python

a context manager, so you can execute code on entering and exiting a block. you use as to assign the return/yield value from the context manager. the simplest example is working with a file

code:
with open("some/path/here", "r") as the_file:
    # do stuff with the_file

# the_file is automatically closed by the __exit__ of the context manager

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Bad Sneakers posted:

can someone explain to me what the with\as statement in python is used for?

disclaimer: i have had exactly one semester of python

it basically lets you wrap some code inside an __enter__ and __exit__ step.

so imagine you have some code and you want it to execute, but there is some generic setup and teardown code that should be executed before and after it runs.

http://effbot.org/zone/python-with-statement.htm

tef
May 30, 2004

-> some l-system crap ->

Bad Sneakers posted:

can someone explain to me what the with\as statement in python is used for?

disclaimer: i have had exactly one semester of python

managing the lifetime of things. what is created for a with statement is destroyed at the end.

it's for when you do

x = open ...
try:
...
finally:
x.close()


i've also used with lock(): and with transaction() as t

brap
Aug 23, 2004

Grimey Drawer
yeah, it's for resources that need to be disposed of when you're done with them like files and DB connections. It's equivalent to the using statement in c#.

Adbot
ADBOT LOVES YOU

FamDav
Mar 29, 2008

fart simpson posted:

imagine reading this with no prior knowledge and then using it in a real program, lol:

http://hackage.haskell.org/package/base-4.6.0.1/docs/Control-Arrow.html

you shouldnt really need to use arrows, and if by the time you need them you can't read the source, see Categories are Arrows and read that class' source and be like "oh, i got the gist" then you need to grind in harder on haskell. The language in the documentation for what makes an arrow is annoying though, so implementing your own might suck :/

also, a is not * -> * -> *, even when its the function type. there its * -> *.

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