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
Doc Block
Apr 15, 2003
Fun Shoe

Pollyanna posted:

why the hell is creating a copy of an object in Objective-C so goddamn complicated

NSArray *array = [otherArray copy];

Is hard?

Adbot
ADBOT LOVES YOU

power botton
Nov 2, 2011

no but its the ugliest loving syntax

Doc Block
Apr 15, 2003
Fun Shoe
nm

Notorious b.s.d.
Jan 25, 2003

by Reene

git clone trooper posted:

no but its the ugliest loving syntax

if you have a problem with ugly syntax objC isn't for you

PrBacterio
Jul 19, 2000

Notorious b.s.d. posted:

if you have a problem with ugly syntax objC isn't for you

is it weird that I think objc's syntax looks loving wonderful in comparison to the abomination that is c++?

PrBacterio
Jul 19, 2000
not that Ill ever write anything in objc because I dont own any apple products but still, in comparison to the pile of poo poo that is c++ it looks like heaven

uG
Apr 23, 2003

by Ralp
how have you been here 13 years and never probated? mods?

Doc Block
Apr 15, 2003
Fun Shoe

PrBacterio posted:

is it weird that I think objc's syntax looks loving wonderful in comparison to the abomination that is c++?

this x1000

[object pleaseDoAThingWith:[SomeClass objectWithFile:filename]];

is so much better than C++.

I always chuckle when C++ programmers complain about objective C's use of square brackets while C++ code looks like someone just randomly mashed the angle bracket, colon, and underscore keys on their keyboard.

FamDav
Mar 29, 2008

Doc Block posted:

this x1000

[object pleaseDoAThingWith:[SomeClass objectWithFile:filename]];

is so much better than C++.

I always chuckle when C++ programmers complain about objective C's use of square brackets while C++ code looks like someone just randomly mashed the angle bracket, colon, and underscore keys on their keyboard.

sorry did you stroke out mid post because wtf is that poo poo

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
objc syntax just takes some getting used to. it's a little verbose but that verbosity allows it to be somewhat self documenting, so it's pretty nice.

once you get used to it and understand why the syntax is the way it is, it'll make a lot more sense.

at first i was like 'wow all these method calls are really weird' but i had no idea what an object was so that was a lot of my problem

a cyberpunk goose
May 21, 2007

objc gives you the oop of c++ bullshit without the impossibly esoteric syntax magic that you can't debug

objc just makes whats really going on more transparent without the vague syntax

idk

i dig it

Doc Block
Apr 15, 2003
Fun Shoe

FamDav posted:

sorry did you stroke out mid post because wtf is that poo poo

It's just a shorter version of

SomeClass *foo = [SomeClass objectWithFile:filename];
[object pleaseDoAThingWith:foo];

The tendency to make Objective C method names really long actually helps readability a lot and makes the code self-documenting to a large degree.

It also makes it nice when you want to do something but don't know the exact method name, since you can usually guess the method name. Or guess the first part of it and see what Xcode's autocomplete suggests.

Shaggar
Apr 26, 2006
java is better cause the syntax is readable and not stupid

Doc Block
Apr 15, 2003
Fun Shoe
LOL java

object = ObjectFactoryFactory().newFactory().newObject()

not stupid at all :rolleyes:

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i really wish apples documentation would list all of the most common methods that you might call on a class/instance instead of just the methods defined in that class.

like if you want to set the display value on NSThing which has an inheritance tree 6 classes deep you have to go up the class tree to figure out how to perform this incredibly common action

power botton
Nov 2, 2011

its a shame you can't code iOS apps in visual studio, and that xmarin poo poo don't count

Doc Block
Apr 15, 2003
Fun Shoe
Hmm yes let me use a not-Objective-C language and a not-LLVM compiler.

NOT
-borate

a cyberpunk goose
May 21, 2007

Doc Block posted:

Hmm yes let me use a not-Objective-C language and a not-LLVM compiler.

NOT
-borate

hmm yes lets rewrite our entire codebase every time we want to port to a platform

a cyberpunk goose
May 21, 2007

NOT

- people who get poo poo done

Doc Block
Apr 15, 2003
Fun Shoe
itym people whose apps look like poo poo on every platform

Bloody
Mar 3, 2013

Doc Block posted:

LOL java

object = ObjectFactoryFactory().newFactory().newObject()

not stupid at all :rolleyes:

hi ive written thousands of lines of java and never needed a factory i guess what im saying is lol you're in the write thread fucko

JewKiller 3000
Nov 28, 2006

by Lowtax

Bloody posted:

hi ive written thousands of lines of java and never needed a factory i guess what im saying is lol you're in the write thread fucko

java attempts to follow and encourage object-oriented programming principles
the most fundamental principle of object-oriented programming is dynamic dispatch
but what if i want to dynamically dispatch even the construction of an object? i won't know which class i need until runtime
java constructors don't do that, hence factories

Nomnom Cookie
Aug 30, 2009



once you understand solid, factories are a natural corollary

Bloody
Mar 3, 2013

idk just dont write such awful code and you wont need such awful hacks

Bloody
Mar 3, 2013

youre all just writing poo poo garbage crud apps anyways

Nomnom Cookie
Aug 30, 2009



i was going to say that i don't but then remembered that i spent the last week working on a poo poo garbage crud app :eng99:

most of my work is more interesting i swear

Bloody posted:

idk just dont write such awful code and you wont need such awful hacks

how do you feel about singletons

Bloody
Mar 3, 2013

singletons are fine in certain situations

like, if you have an object that there should never be more than one of, use a singleton

Nomnom Cookie
Aug 30, 2009



when you can't have more than one, use a singleton...the only example i can think of is R. R interpreter state is process-global so it's impossible to have more than one. if u try then u'll probably segfault

even then it might make sense for the public interface to be regular objects that coordinate their access to the singleton

if you shouldn't have more than one, just only make one instance

Bloody
Mar 3, 2013

sometimes you're programming with idiots and you need to sledgehammer them into only having one instance

Doc Block
Apr 15, 2003
Fun Shoe
Or you're writing in Objective C, where singletons are pretty common. Like, you find out if a file exists by asking the NSFileManager class's defaultManager singleton.

Shaggar
Apr 26, 2006
IO access points should usually be singletons (ex: db connection/session providers) and configuration classes/parameters should be singletons either cause their read only, so why have more than 1, or cause you need to have a single point to lock for doing global writes (really that's just more IO).

Morkai
May 2, 2004

aaag babbys
but wouldn't a static class for config objects work just as well? i use static classes all the time for stuff that only needs to exist in memory once. and singleton for io connections sorta makes sense but only if you need blocking operations, but why block on db access?

Morkai
May 2, 2004

aaag babbys
or is java singleton done in a way I'm not understanding? i am c#.net

Bloody
Mar 3, 2013

singleton makes use of static to enforce a single instance of an object globally

Shaggar
Apr 26, 2006
its not about blocking complete access to the db, it would be like maintaining a single connection pool and feeding back free connections rather than having every bit of your code constantly opening new ones all over the place. the pool manager and the datasource config would be singletons.

and a static class for config would be a singleton

Nomnom Cookie
Aug 30, 2009



Bloody posted:

sometimes you're programming with idiots and you need to sledgehammer them into only having one instance

nah the hard part is convincing idiots to not use singletons

Nomnom Cookie
Aug 30, 2009



Doc Block posted:

Or you're writing in Objective C, where singletons are pretty common. Like, you find out if a file exists by asking the NSFileManager class's defaultManager singleton.

nsfilemanager isn't a singleton

Morkai
May 2, 2004

aaag babbys

Shaggar posted:

its not about blocking complete access to the db, it would be like maintaining a single connection pool and feeding back free connections rather than having every bit of your code constantly opening new ones all over the place. the pool manager and the datasource config would be singletons.

and a static class for config would be a singleton

got it, different terms for the same result.

Doc Block
Apr 15, 2003
Fun Shoe

Nomnom Cookie posted:

nsfilemanager isn't a singleton

NSFileManager is a class. defaultManager is a singleton instance of NSFileManager, though you can make your own non-singleton NSFileManager instances if you need to do something weird.

So I guess it's more of a shared, global instance, but 99.999% of programs only use the global instance, so it's effectively a singleton.

Doc Block fucked around with this message at 17:32 on Oct 6, 2013

Adbot
ADBOT LOVES YOU

Notorious b.s.d.
Jan 25, 2003

by Reene

JewKiller 3000 posted:

java attempts to follow and encourage object-oriented programming principles

the most fundamental principle of object-oriented programming is dynamic dispatch

but what if i want to dynamically dispatch even the construction of an object? i won't know which class i need until runtime

java constructors don't do that, hence factories

this explanation is both concise and correct

  • Locked thread