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
Dr. Honked
Jan 9, 2011

eat it you slaaaaaaag

an idiot hell fucker posted:

I myself have written JavaScript for more than three years without ever defining an object. The technique explained on this page is the first practical use of programmer-defined objects I've found.

Since the only other programming languages I know are Commodore 64 Basic (which is not object oriented, to put it mildly) and Perl (which doesn't need to be object oriented) and since I don't have any formal training in programming I cannot write a general introduction to objects and object oriented programming. Therefore a quick overview will have to suffice.

http://www.quirksmode.org/js/associative.html

Adbot
ADBOT LOVES YOU

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

fuckin' quirksmode

qntm
Jun 17, 2009

Soricidus posted:

I like the way java does file structure. one public class per file, one package per directory, names must match. it has downsides too and the visibility rules could be better but whenever I read about poo poo like f# I realise how good I have it

Java being one of the very first PLs I learned, it always boggles my mind a bit when any language doesn't do this

Perl has packages (code grouped by namespace) and modules (code grouped by file) being entirely separate things, then overloads the :: separator to refer to them alternately depending on context, or sometimes both at once

You'd think this would mean developers, or at least CPAN module developers, would try to keep packages and modules harmonised so that nobody has to care about this distinction but NOPE

Brain Candy
May 18, 2006

Barnyard Protein posted:

but it feels... not right

because welding xml into the heart of your application is always a bad choice

you can go the other way though; JAX-B and friends can use your data model when they [un]marshall

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
quirksmode is a great place to feel ashamed of liking js

qntm
Jun 17, 2009

I ask you, is there a worse code smell than people using "theValue" and "theStatus" for variable names

qntm
Jun 17, 2009

uncurable mlady posted:

quirksmode is a great place to feel ashamed of liking js

http://www.quirksmode.org/js/function.html posted:

This is a function:

JavaScript code:
function example(a,b) {
	number += a;
	alert('You have chosen: ' + b);
}
It is called like this:

code:
example(1,'house')

:raise:

Dr. Honked
Jan 9, 2011

eat it you slaaaaaaag
i've never seen quirksmode before. it's quite a thing

Jerry Bindle
May 16, 2003

Brain Candy posted:

because welding xml into the heart of your application is always a bad choice

you can go the other way though; JAX-B and friends can use your data model when they [un]marshall

yeah i've gotten as far as generating classes with xjc, and marshalling/unmarshalling with JAXB. i'm stuck at figuring how how to connect the generated classes, the model, to the view such that the view automatically updates when the model changes. maybe this is such a simple problem that the answer is obvious, idk.

Shaggar
Apr 26, 2006

Barnyard Protein posted:

who does the publishing then? the code that is making changes to the model (ie the controller)?

the controller.

Shaggar
Apr 26, 2006
really though you should be using wpf if your doing desktop development.

Shaggar
Apr 26, 2006
the controller gets a request, figures out what the user wants, then finds the data the user wants, and shoves it into the view.

you can also create viewmodels to house display logic for the model. this prevents you from contaminating your model with logic to do with display and removes logic from your view which can reduce maintenance woes

for example if you have a model object that contains a list of things and if the list is empty you want to hide a section in the view. you could create the logic in your view to hide the section if list.size()==0 but you could also instead create a viewmodel that has a method bool showWhateverSection() that the view calls instead.

any kind of logic or display that might be reusable you can put into the viewmodel to prevent having to deal w/ that logic in the view. of course if you're using something that supports partial views they make view component reuse easy so its not that big of a deal.

but if you've got a person model object and in 15 different views you've got model.firstName()+" "+model.lastName() where you want the display name and suddenly you decide you want lastname, firstname instead of changing it in each view you just change it in the getDisplayName() method of you're viewmodel.

Shaggar
Apr 26, 2006

Brain Candy posted:

because welding xml into the heart of your application is always a bad choice

you can go the other way though; JAX-B and friends can use your data model when they [un]marshall

jax b is fine but the scenarios where you're actively using jax b directly instead of as part of another framework (ex: cxf) are uncommon

Shaggar fucked around with this message at 03:09 on Jun 10, 2015

comedyblissoption
Mar 15, 2006

qntm posted:

I ask you, is there a worse code smell than people using "theValue" and "theStatus" for variable names
theStatus is helpful to differentiate the status in global scope as opposed to aStatus which is just in local function scope

Brain Candy
May 18, 2006

comedyblissoption posted:

theStatus is helpful to differentiate the status in global scope as opposed to aStatus which is just in local function scope

only when you are using tools that don't colorize that for you

comedyblissoption
Mar 15, 2006

that doesnt help much when you need to print out your code

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

here's a nickel kid, buy yourself an inkjet

comedyblissoption
Mar 15, 2006

coloured ink is worth more than my blood by volume

Valeyard
Mar 30, 2012


Grimey Drawer
Switching between camel case, hyphens and underscores randomly is pretty annoying

comedyblissoption
Mar 15, 2006

camel case is such idiot garbage prized by those who value screen real estate over being able to loving read anything

im the idiot in the codebase who randomly omits vowels on identifiers for no loving reason

Bloody
Mar 3, 2013

Valeyard posted:

Switching between camel case, hyphens and underscores randomly is pretty annoying

why are you touching math code

Bloody
Mar 3, 2013

comedyblissoption posted:

camel case is such idiot garbage prized by those who value screen real estate over being able to loving read anything

im the idiot in the codebase who randomly omits vowels on identifiers for no loving reason


Bloody posted:

why are you touching math code

JewKiller 3000
Nov 28, 2006

by Lowtax
a good name for a function is "f"
when that's already taken, try "g"

for local variables, consider "x"
already used? give some thought to "y"

comedyblissoption
Mar 15, 2006

xs and ys for collections are fine too

btn and pn for button and pane are not fine

comedyblissoption
Mar 15, 2006

cnt

Bloody
Mar 3, 2013

running out of letters? consider capitalizing letters. now you have twice as many possible variables.

Valeyard
Mar 30, 2012


Grimey Drawer

Bloody posted:

running out of letters? consider capitalizing letters. now you have twice as many possible variables.

This reminds me of another thing I hate, when the same variable is used multiple times in the same scope but for different reasons. Like at some point in the logic that value isn't needed anymore, so next time we need a new variable let's just use that old onwt

AWWNAW
Dec 30, 2008

Valeyard posted:

This reminds me of another thing I hate, when the same variable is used multiple times in the same scope but for different reasons. Like at some point in the logic that value isn't needed anymore, so next time we need a new variable let's just use that old onwt

haha don't you know this is way more efficient. learn 2 optimize scrub lord

fritz
Jul 26, 2003

Soricidus posted:

I like the way java does file structure. one public class per file, one package per directory, names must match. it has downsides too and the visibility rules could be better but whenever I read about poo poo like f# I realise how good I have it

i only recently started using java, the last time i looked at it was in literally 1995, and there are still some mysteries to me about how packages and classes interact with files and directories, and how jars work with other jars and how any of the build systems work, but i really do like the discipline that it enforces

VikingofRock
Aug 24, 2008




I dunno, if your code is generic enough sometimes there's not really anything better to call your variables. Like if your function takes an arbitrary function as a parameter, why not call that function f?

Bloody
Mar 3, 2013

VikingofRock posted:

I dunno, if your code is generic enough sometimes there's not really anything better to call your variables. Like if your function takes an arbitrary function as a parameter, why not call that function f?

http://www.stat.unc.edu/faculty/hurd/stat185Data/progdoc.html

click any link on this page

fritz
Jul 26, 2003


there are actual comments in some of those files and they appear relevant

VikingofRock
Aug 24, 2008





Okay yeah those are bad, but click on any of these links:

http://www.cplusplus.com/reference/functional/function/function/
http://www.cplusplus.com/reference/functional/bind/
http://www.cplusplus.com/reference/algorithm/copy_if/
http://www.cplusplus.com/reference/algorithm/is_partitioned/
http://www.cplusplus.com/reference/algorithm/find/
http://www.cplusplus.com/reference/algorithm/min/
http://www.cplusplus.com/reference/algorithm/transform/

The majority of the arguments to those functions are named things like 'a', 'b', 'fn', 'op', 'pred', etc, and it's perfectly readable. It's definitely not always a good idea to call a function 'f', but it's not always a bad idea either.

I also think that in math/physics code, it's perfectly legitimate to give a variable a name like 'phi', 'theta', or 'rho' in a context where those have widely accepted meanings. For example if you have a function in some physics code which takes a point in spherical coordinates, it's totally cool to call the parameters 'r' (for the radial distance), 'theta' (for the polar angle), and 'phi' (for the azimuthal angle).

comedyblissoption
Mar 15, 2006

Valeyard posted:

This reminds me of another thing I hate, when the same variable is used multiple times in the same scope but for different reasons. Like at some point in the logic that value isn't needed anymore, so next time we need a new variable let's just use that old onwt
mutability by default is the source of a lot of bugs

seeing this also usually means the function is way too loving big

function size too big should be a configureable compiler warning for all compilers

comedyblissoption fucked around with this message at 04:45 on Jun 10, 2015

VikingofRock
Aug 24, 2008




Valeyard posted:

This reminds me of another thing I hate, when the same variable is used multiple times in the same scope but for different reasons. Like at some point in the logic that value isn't needed anymore, so next time we need a new variable let's just use that old onwt

Agreed, this is awful. Does anyone know whether LLVM can optimize away stuff like that? (my guess is yes)

brap
Aug 23, 2004

Grimey Drawer

qntm posted:

I ask you, is there a worse code smell than people using "theValue" and "theStatus" for variable names

I have a coworker who uses it for singletons but I find it slightly ugh

like if you have some get-only property with the same name as the class I already know it's a singleton

VikingofRock posted:

Agreed, this is awful. Does anyone know whether LLVM can optimize away stuff like that? (my guess is yes)

One of the first rules of good programming is to write readable code instead of doing hosed up poo poo because you think it'll save something meaningless like a variable allocation. wait until a bottleneck becomes apparent before making sacrifices to readability/maintainability to improve performance.

brap fucked around with this message at 04:52 on Jun 10, 2015

Luigi Thirty
Apr 30, 2006

Emergency confection port.

trip report from ill-advised trip to x86 assemblyland: this is the worst poo poo but at least I can goatse people with a floppy disk on a 286 or better VGA-compatible PC

how did anyone get anything done with this architecture

JewKiller 3000
Nov 28, 2006

by Lowtax

VikingofRock posted:

Agreed, this is awful. Does anyone know whether LLVM can optimize away stuff like that? (my guess is yes)

any reasonable compiler for any reasonable language will optimize that away, yes. of course if we're talking about C, all bets are off (simple code? sure. crazy pointer manip the compiler can't reason about? lolol nope)

fritz
Jul 26, 2003

VikingofRock posted:

Agreed, this is awful. Does anyone know whether LLVM can optimize away stuff like that? (my guess is yes)

optimize it to what?

Adbot
ADBOT LOVES YOU

JewKiller 3000
Nov 28, 2006

by Lowtax

Luigi Thirty posted:

how did anyone get anything done with this architecture

very carefully, lol

  • Locked thread