South Africa Flag logo

South African Skeptics

November 12, 2019, 12:47:51 PM
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Go to mobile page.
News: Please read the forum rules before posting.
   
   Skeptic Forum Board Index   Help Forum Rules Search GoogleTagged Login Register Chat Blogroll  
Pages: 1 2 [3] 4   Go Down
  Print  
Author Topic:

On programming

 (Read 8595 times)
0 Members and 1 Guest are viewing this topic.
benguela
Full Member
***

Skeptical ability: +3/-0
Offline Offline

Posts: 223


An infinitesimal subset of the observable universe


benguela
WWW
« Reply #30 on: June 01, 2011, 20:35:00 PM »

Hmm, the only way I can think of to create a linked list using Java is if each node is itself an instance of the same object class that references the node after it (and the node before if it’s doubly-linked). 

See, not that difficult. But wow do they struggle with this.

Logged
BoogieMonster
NP complete
Hero Member
*****

Skeptical ability: +19/-1
Offline Offline

Posts: 3108



« Reply #31 on: June 01, 2011, 23:51:44 PM »


Being strictly OO, Java doesn’t recognise pointers, which is how I’d do this normally.  Then again, everything in Java except operators...

Forgive my rude assumption about your knowledge here but actually Java has non-object types, there's both a primitive int type, and an Integer class. A lot of the primitives you'd find in C/C++ are available as types in Java too: short, long, char, etc...

Also, (memory don't fail me now...) unless specifically coded otherwise, object variables are just references, so you can get your "pointer like" linked list by accident... A fact many Java novices don't grok at first sight, until it's "pointed" out.
Logged
Mefiante
Defollyant Iconoclast
Hero Member
*****

Skeptical ability: +61/-9
Offline Offline

Posts: 3755


In solidarity with rwenzori: Κοπρος φανεται


WWW
« Reply #32 on: June 02, 2011, 11:38:10 AM »

Are you saying that Java actually supports pointer types, even if only inadvertently?  Surely you wouldn’t be able to dereference such a pointer explicitly in Java!  And wouldn’t all of that fly directly in the face of the abstractions that OOP is all about!?

I’m hardly a Java boffin, not having used the language much at all.  I could be wrong here, but it is my impression that in Java even “primitive” data types like int come bundled with some methods, e.g., “toString()”.  If so, they’re hardly primitives in the sense of C, Pascal, BASIC, etc.  Or is that the “Integer” class I’m thinking of?

As for object variables being references, that is true for all OO languages I’m aware of.  It’s just that the languages’ syntax rules hide the pointer nature of object variables from the programmer.  A disassembly of Delphi or C++ code (or Java to byte code or C# to MSIL) makes it quite plain that objects are always passed by reference in the compiled code.  If the programmer actually intends passing an object by value to a function, the function transparently creates a local copy (not on the stack, though!) of the object from the original which it then operates on and later destroys, but the original is still passed by reference, i.e. as the object’s base pointer.  What I was driving at is that Java, like C#, adheres very strictly to OO standards, whereas other OO languages not so much.  Although not good practice, one can mix OOP with straight procedural code in C/C++ and Delphi.  As far as I know, in Java or C# you cannot do this, or other wild things such as for example directly accessing an object’s VMT, but you can in Delphi or C++ if you know how to use pointers and how the objects are represented in memory.  (You might actually want to do the latter for detailed on-the-fly debugging purposes in certain circumstances.)

'Luthon64
Logged
BoogieMonster
NP complete
Hero Member
*****

Skeptical ability: +19/-1
Offline Offline

Posts: 3108



« Reply #33 on: June 02, 2011, 14:55:29 PM »

I’m hardly a Java boffin, not having used the language much at all.  I could be wrong here, but it is my impression that in Java even “primitive” data types like int come bundled with some methods

Nope.

Quote
Or is that the “Integer” class I’m thinking of?

Yup.

Quote
It’s just that the languages’ syntax rules hide the pointer nature of object variables from the programmer.

That's my point, to make a new object you need to invoke "new" explicitly (iirc). My comment was about novices who fail to realise that "MyObject b = a;" is not a value copy, but results in two references to one object (if it wasn't a primitive).
Logged
Deezil
Moo-Moo
Newbie
*

Skeptical ability: +0/-0
Offline Offline

Posts: 28



johan.burke DeezilDude
WWW
« Reply #34 on: June 02, 2011, 15:38:34 PM »

omg ... reading this thread just made me realise again how glad I am I got out of programming a looong time ago.

Thanx guys!

P.S  Used to program in Cobol in the late 90's and doddled a bit with java and c# while studying in the mid 00's (nothing hectic though ... reading the two posts above was like WTF!!
Logged
Brian
Hero Member
*****

Skeptical ability: +8/-1
Offline Offline

Posts: 1367


I think therefor I am, I think


« Reply #35 on: June 02, 2011, 17:14:40 PM »

you programmers talk funny.
Logged
Mefiante
Defollyant Iconoclast
Hero Member
*****

Skeptical ability: +61/-9
Offline Offline

Posts: 3755


In solidarity with rwenzori: Κοπρος φανεται


WWW
« Reply #36 on: June 02, 2011, 19:23:19 PM »

Nope.



Yup.
Okay, thanks for clearing that up.  As said, I’ve not used Java much, and that was long ago.

That's my point…
Yes, I now see what you mean.  When using pointers, the novice easily confuses the pointer (i.e. the reference) with the thing it points at.  Assigning one pointer to another doesn’t magically create another copy of the thing the first pointer references; rather, one now has two pointers referencing the same thing.  Just goes to show how easily familiarity lets one forget these teething problems. Grin



you programmers talk funny.
No, we do ~     Tongue

'Luthon64
« Last Edit: June 02, 2011, 19:48:10 PM by Mefiante, Reason: Syntax » Logged
benguela
Full Member
***

Skeptical ability: +3/-0
Offline Offline

Posts: 223


An infinitesimal subset of the observable universe


benguela
WWW
« Reply #37 on: June 21, 2011, 16:35:49 PM »

I'm busy giving my course at one of the 4 major banks, as I mentioned before, the first assignment is to read in a set of n numbers from a file and implement the formulas for calculating the mean and standard deviation.

After 3 hours of "coding" this is what I got from a "programmer", earning a shitload of money, today.

mean=(160+591+114+229+230+270+
128+1657+624+1503)/10;

std_dev = (sqrt(((160-mean)*(160-mean)) +               
((591-mean)*(591-mean))+               
((114-mean)*(114-mean))+               
((229-mean)*(229-mean))+               
((230-mean)*(230-mean))+               
((270-mean)*(270-mean))+               
((128-mean)*(128-mean))+               
((1657-mean)*(1657-mean))+               
((624-mean)*(624-mean))+               
((1503-mean)))/10);


He didn't bother reading from a file, didn't cater for "n" numbers, just decided on hardcoding 10 numbers, didn't loop through a data structure like say an array  WTF!!

Seriously, this is the calibre of paid professionals that attend my classes.  Angry


Logged
Mefiante
Defollyant Iconoclast
Hero Member
*****

Skeptical ability: +61/-9
Offline Offline

Posts: 3755


In solidarity with rwenzori: Κοπρος φανεται


WWW
« Reply #38 on: June 21, 2011, 16:52:39 PM »

For a supposed professional, that is truly shocking*.  Does the offender have any other formal programming qualifications that you know of?  I hope that you have sufficient grounds to fail this pathetic attempt on the grounds of not reading the instructions (read: “software specification”) attentively enough, if nothing else.

Then again, I look at the anorexic capabilities of some individuals in certain IT departments and I am forced to conclude that to get and keep their jobs, they must be hellspawn in league with Lucifer himself, come to wreak havoc and disruption… Roll Eyes

'Luthon64



* When carrying code over several lines, an operator (like a plus sign) should always lead each new line. Wink
Logged
st0nes
Hero Member
*****

Skeptical ability: +10/-1
Offline Offline

Posts: 942



mark.widdicombe1
WWW
« Reply #39 on: June 22, 2011, 07:34:51 AM »

* When carrying code over several lines, an operator (like a plus sign) should always lead each new line. Wink
Why?
Logged
Mefiante
Defollyant Iconoclast
Hero Member
*****

Skeptical ability: +61/-9
Offline Offline

Posts: 3755


In solidarity with rwenzori: Κοπρος φανεται


WWW
« Reply #40 on: June 22, 2011, 08:36:10 AM »

’Twas actually a joke — picking on something minor and neglecting the far more severe issue.  Nonetheless, the presence of a leading operator is a definite indicator that code was carried over from the preceding line.  Indentation further enhances this.  It makes for a good, readable coding style, analogous to the way paragraphs make ordinary text easier to read and follow.

ETA:  In any case, if the code was submitted exactly as benguela has shown it, the “std_dev = ” expression, despite being hard-coded, contains two separate errors.

'Luthon64
Logged
st0nes
Hero Member
*****

Skeptical ability: +10/-1
Offline Offline

Posts: 942



mark.widdicombe1
WWW
« Reply #41 on: June 22, 2011, 08:45:21 AM »

’Twas actually a joke — picking on something minor and neglecting the far more severe issue.  Nonetheless, the presence of a leading operator is a definite indicator that code was carried over from the preceding line.  Indentation further enhances this.  It makes for a good, readable coding style, analogous to the way paragraphs make ordinary text easier to read and follow.
OK, fair enough I suppose.  I always code with the operator at the end of the line and rely on indentation to make clear that the line is a continuation.  It seems more 'English like' like that, and therefore easier (for me) to follow.  Different strokes for different folks, I guess.
Logged
Mefiante
Defollyant Iconoclast
Hero Member
*****

Skeptical ability: +61/-9
Offline Offline

Posts: 3755


In solidarity with rwenzori: Κοπρος φανεται


WWW
« Reply #42 on: June 22, 2011, 08:57:12 AM »

Style guides for various scientific journals and other scientific documents require that mathematical expressions should follow the convention I outlined re leading operators when such expressions are broken across multiple lines, and for the same reason I mentioned.  Thus, there’s also a consistency aspect to consider.

'Luthon64
Logged
st0nes
Hero Member
*****

Skeptical ability: +10/-1
Offline Offline

Posts: 942



mark.widdicombe1
WWW
« Reply #43 on: June 22, 2011, 09:10:36 AM »

Style guides for various scientific journals and other scientific documents require that mathematical expressions should follow the convention I outlined re leading operators when such expressions are broken across multiple lines, and for the same reason I mentioned.  Thus, there’s also a consistency aspect to consider.
I don't write for scientific journals, so I am unaware of their style guides.  In business applications the opposite convention is usually applied.  That said, every company I have worked for has had their own coding conventions, some of which are totally without reason.  You can do work for one company which insists that indents are spaces, then work for another company which insists that they are tabs.  There's a reason for only using spaces, but no coherent reason for only using tabs, but it's their money so we tow the line.
Logged
BoogieMonster
NP complete
Hero Member
*****

Skeptical ability: +19/-1
Offline Offline

Posts: 3108



« Reply #44 on: June 22, 2011, 11:07:18 AM »

After 3 hours of "coding" this is what I got from a "programmer", earning a shitload of money, today.

How much is a shitload? I can meet or *even* exceed that kind of quality.

Edit: *
Logged
Pages: 1 2 [3] 4   Go Up
  Print  


 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
Page created in 0.54 seconds with 24 sceptic queries.
Google visited last this page February 14, 2019, 09:05:27 AM
Privacy Policy