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
tef
May 30, 2004

-> some l-system crap ->

PleasingFungus posted:

That's not what 'pass-by-reference' means.

When a function is 'pass-by-reference', the arguments are passed as pointers ('references') to the actual values, rather than the values proper. This means that you can modify the arguments (by dereferencing the pointer), which can be good or bad. It also means that you don't have to copy the values from one space in memory to another, which is important when dealing with large variables (arrays, big objects, etc).

In C and similar languages, you can actually work with pointers, so you can make the decision explicitly. (void foo(int a, int * b) - a is passed by value, b is passed as a pointer.) Java doesn't have user-defined pointers, so the language has to make the decision for you. The decision they made for primitives (ints, bools, etc) was 'pass-by-value'. In "int a = 1; foo(a); print(a)", the result printed will always be '1', no matter what happens in foo(). This is the primary appeal of pass-by-value: you can guarantee that variables passed as function arguments remain unchanged when you return to your own scope. It's a reasonable default.

Java objects, on the other hand, are passed by reference: if you pass in an object to a function & modify it therein, you can retrieve the modified value from the calling function. That means it's possible to 'simulate' pointers in Java by using objects. E.g. "class IntPointer { int containedInt; } IntPointer a = new IntPointer(); foo(a); print(a.containedInt) - the result could be anything! This is of course clunky & overly verbose, but if you like Java, that is probably right up your alley!

The (primary) reason that Java doesn't have pointers is that pointers let you freely tinker with memory. Unlike C, Java's memory is managed - instead of the programmer having to handle memory allocation & deallocation, it's abstracted into an operation of the JVM. That means, as another consequence, that the programmer can't be allowed to tinker with memory freely, because that would break the abstraction that lets Java's memory management works.


^^ This paragraph is the actual answer you were looking for, feel free to skip the rest.

*java objects are actually pointers with a very constrained set of operations that can be performed on them.

pass by reference isn't the same as passing a reference by value.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
java is call by value. objects are stored as reference.

in a pass by reference language you can write a swap function.

actual languages that are pass by ref: perl

tef
May 30, 2004

-> some l-system crap ->
oh god what am I doing

tef
May 30, 2004

-> some l-system crap ->

echinopsis posted:

tef once recommended me a book on coding, I wonder what it was?

I want to read meta coding poo poo. like, not hardcore theory but explain why gotos are bad to me like I'm 5 years old

it was the practice of programming by kernighan and pike

tef
May 30, 2004

-> some l-system crap ->

chumpchous posted:

my company has been asking me if i want to move over to development full time. it's tempting because i honestly enjoy it a lot more than my real job (editing/coloring), but then i go into cavern of cobol or stack overflow and realize how hilariously underqualified i am to do any kind of real programming work.

i have no qualifications to do programming. most programmers have no idea what they are doing.

if you can write a for loop, and can count you are doing better than many people i've interviewed.


it is much easier to be a programmer if you stop caring about the quality of work you produce. if you get more money and have more fun doing code, just do it and drink yourself into oblivion to deal with the insecurity and ennui

tef
May 30, 2004

-> some l-system crap ->

Moist von Lipwig posted:

i wish i had enough programming knowledge to dig really deep into like assembly it seems like the closer you get to raw silicon the closer you are to pure math/physics/enlightenment :lsd:

how bout this book ? http://www.nand2tetris.org

tef
May 30, 2004

-> some l-system crap ->

echinopsis posted:

can't pointers to pointers to pointers be used for some fancy efficient tricky code?


also I still can't even get my head around how even the most simple quine works... I need baby's first Quine written in basic and then run a debugger at 3 lines per hour just to follow it

a quine is a neat trick. from google this seems ok http://www.madore.org/~david/computers/quine.html


i also found this neat quine in python :3:

quine = 'quine = %r\r\nprint quine %% quine'
print quine % quine

tef
May 30, 2004

-> some l-system crap ->

FamDav posted:

tef seriously you just need to find something that excites you.

i'm dead on the inside.

quote:

are there no jobs in the uk that you would find stimulating?

http://www.theonion.com/articles/find-the-thing-youre-most-passionate-about-then-do,31742/

tef
May 30, 2004

-> some l-system crap ->

Martytoof posted:

every language that isn't c-style looks weird as gently caress

i got over it for objective-c because it's mostly c-style with a bunch of brackets, but i'm having a hard time with python and stuff

and then i tried to learn ruby on rails because i wanted to make a quick website and everything about it was weird as gently caress. i am a little depressed that i can't pick this stuff up easily anymore :(

python and ruby are quite different underneath, ruby is more like smalltalk, python is like a broken scheme. it's ok to be a little frustrated you can't move from one to the other

tef
May 30, 2004

-> some l-system crap ->

THC posted:

smoke weed

every day, https://www.youtube.com/watch?v=kHXaMJ-ED6g


smoke weed everyday, smoke smoke weed weed weed, smoke smoke weed smoke weed weed

https://www.youtube.com/watch?v=IIIpExVf-5I

tef
May 30, 2004

-> some l-system crap ->

chumpchous posted:

i dunno when i was doing manual labor i was so tired all the time the only thing i could stress about was my job. now i have tons of surpluss energy but no surplus motivation and my job isn't that stressful so instead i stress about how generally unhappy + unhealthy + terrible my life is.

hedonistic treadmill. woo

tef
May 30, 2004

-> some l-system crap ->

FamDav posted:

we encounter so much mediocrity in our day to day lives that it infuriates and depresses us that people who do not put in a sincere effort can be rewarded as well or even better than us. we have to accept that our reward for hard work and persistence is the knowledge that we took the more difficult path and succeeded.

only then will you find happiness and comfort.

haha no gently caress that: slack off, get paid

tef
May 30, 2004

-> some l-system crap ->

gucci void main posted:

nothing you learn in college involving c++ is actually of use hth

also lol 12k, even in eurodollars

nothing you learned was ever of use sure, but i'm not your poor life choices are transitive

tef
May 30, 2004

-> some l-system crap ->
prolog

tef
May 30, 2004

-> some l-system crap ->

noice

tef
May 30, 2004

-> some l-system crap ->

Ericadia posted:

So what specific things in C++ do people hate? Like, name the #1 thing that makes you wish you were dead:

as someone who has never really touched c++, but loathes it:

despite smarter programmers than me espousing the virtuous nature of generic programming, to me it's still "an octopus made by nailing legs onto a dog". unfortunately, we're still nailing legs to it, and in 20 years time it will be a millipede. nothing will ever be removed from c++, only added atop.

c++, as many of its apologists recite, is "pay for what you use", in the sense that if you are punished for exactly how many features of c++ you use. these payments compound. c++ is a way of sacrificing programmers for the holy grail of efficient code. additionally, every company that uses c++ will use a different subset, and if you're lucky, their own homebrew standard library.

if i had to pick two languages that were closest in culture to c++, it would be php and lisp.

php is ubiquitous, well known, and well established in industry. although some of the design decisions are beyond questionable, php, like c++ won't be going away any time soon. much of the code written in both is unsurprisingly crap, and the languages punish both the ignorant and the knowledgable.

lisp in that it's full of smug weenies, hilariously fragmented, with a bloodlust for meta-programming, outdoing each other with clever hacks, torturing the language into a useable one. why write something simple that works at a price of verbosity, when you can write something that superficially looks simple but is implemented in rube-goldberg fashion, at a price of sanity.


c++ is like a swiss army knife of power tools. it's impossible to use without harming yourself.

really, i feel too dumb to use c++.

tef
May 30, 2004

-> some l-system crap ->
c++ is a language in which every program is a horror, but you can write efficient horrors if you're a smart-rear end.

tef
May 30, 2004

-> some l-system crap ->

more like dICK posted:

so like most people who rant about c++

not living in jonestown

tef
May 30, 2004

-> some l-system crap ->

more like dICK posted:

I feel like its still 1998 when I see posts like that :allears:

unfortunately some people I know still maintain code as if it were 1998. we can't all be working on llvm and clang.

tef
May 30, 2004

-> some l-system crap ->

more like dICK posted:

Some programmers I know are severely underpaid and miserable, but that doesn't make it correct to say that all programmers are

we're both talking about the games industry ?

tef
May 30, 2004

-> some l-system crap ->
indent plan

tef
May 30, 2004

-> some l-system crap ->
you're not forced to handle exceptions though, the whole point is that any line can throw one so you don't have to be explicit which one.

checked exceptions are a poor implementation of option types.

tef
May 30, 2004

-> some l-system crap ->
now shaggar has to argue against making error handling explicit and enforced by the compiler, to a level where you can clearly see where errors are returned and how they are handled.

and then make an argument that doing that in a way so broken even microsoft wouldn't touch is better

tef
May 30, 2004

-> some l-system crap ->

tef
May 30, 2004

-> some l-system crap ->
oh I forgot shaggar wants checked exceptions and not option types because he's anti union

tef
May 30, 2004

-> some l-system crap ->
MY NON LOCAL CONTROL FLOW

tef
May 30, 2004

-> some l-system crap ->

Shaggar posted:

checked exceptions ensure that developers deal with them instead of ignoring them.

i want to believe

tef
May 30, 2004

-> some l-system crap ->
even the java library doesn't make effective use of them

tef
May 30, 2004

-> some l-system crap ->

JewKiller 3000 posted:

close thread, a better post than this cannot be made

i can't remember who i stole it from either

tef
May 30, 2004

-> some l-system crap ->

PleasingFungus posted:

java question time. my understanding is that, taking advantage of the fact that java strings are immutable, identical strings are stored at the same location in memory. e.g.:
code:
String foo = "butts";
String bar = "butts"; //should be stored in the same place as foo!
googling tells me this is called "string interning", and that java's implementation is called the 'string pool'. anyway.

wouldn't that imply, then, that the == / != operators would work for comparing strings? I'd assumed that ==/!= were just comparing the values of the internal pointers (and wiki agrees with me here), so...?

they work for comparing memory addresses, so if all your strings have unique locations in memory, yes you can use it to check equality. the assumption that every string you create has only one possible address is not a pleasant one.

if you need to check string equality, use equals. if you need to check object identity, use ==. if you're needing to check object identity on strings, you will be better off using an enum to represent your constants, not strings.

tef
May 30, 2004

-> some l-system crap ->
enums also make great singletons

tef
May 30, 2004

-> some l-system crap ->
it's ok we all know you're a programmer

tef
May 30, 2004

-> some l-system crap ->

dur posted:

i'm a bad programmer. this is how i'm making an xml file in python

Python code:
fcline = '\t<FeatureClass name=\"%s\" oid_field=\"ObjectID\">\n'
fline = '\t\t<Feature oid=\"%s\" action=\"added\" />\n'

outFile.write(fcline % 'MISC_PLAN_METRICS')
for row in arcpy.SearchCursor('MISC_PLAN_METRICS_Work'):
	outFile.write(fline % row.ObjectID)
outFile.write('\t</FeatureClass>\n')
	
outFile.write(fcline % 'Park_Boundaries')
for row in arcpy.SearchCursor('Park_Boundaries_Work'):
	outFile.write(fline % row.ObjectID)
outFile.write('\t</FeatureClass>\n')

outFile.write(fcline % 'Hydrology')
for row in arcpy.SearchCursor('Hydrology_Work'):
	outFile.write(fline % row.ObjectID)
outFile.write('\t</FeatureClass>\n')
it works though

my boss did this. he then fixed it by writing another program to read the broken html and try and escape the text he'd forgotten

if you can't be arsed to find a library to write xml, at least escape the goddam values you put in i.e

code:
from xml.sax.saxutils import escape, quoteattr

def fline(obj_id):
    return '\t\t<Feature oid=\"%s\" action=\"added\" />\n' % quoteattr(obj_id)

...
    outFile.write(fline(row.ObjectID))
future you will thank you for making some effort.

tef
May 30, 2004

-> some l-system crap ->
use wasabi

tef
May 30, 2004

-> some l-system crap ->
protocoffeescript

tef
May 30, 2004

-> some l-system crap ->
https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java#L213

tef
May 30, 2004

-> some l-system crap ->
aka: all our html templates go in this directory, all our sql goes in another, and then what's left over goes in the last directory

tef
May 30, 2004

-> some l-system crap ->
and curious to see what the thread makes of http://www.stanford.edu/~ouster/cgi-bin/papers/fiz.pdf

tef
May 30, 2004

-> some l-system crap ->
in the facebook screen I had today, I stumbled over the screen question. got the right answer in the end, it was kinda obvious and I felt dumb.

they also asked me what my ideal job would be. i said 'destroying capitalism'. i mean what would be the point if only I got to have an ideal job and be free from wage slavery.

i said i would settle for destroying timezones and be lauded by programmers for the rest of my life.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
eliminate all utc offsets

  • Locked thread