Are Some Programming Languages More Aspie than Others?

Page 2 of 5 [ 72 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

09 Feb 2009, 12:35 pm

You gave a code fragment. I critiqued that code fragment. Your "explanations" appeal mainly to things not shown in the code fragment.

I suggest you take all your comments above, and put them in your code as comments.

==========

Returning "-1"? Don't you mean returning "-1.0"?

I do hope that you do not REALLY use std::numeric_limits<double>::max() the way you have suggested. Do you really rely on positive infinity as a return value? You must be certain that FP handling is set to use affine infinity, otherwise there will be an FP exception error when you come to compare your (nominally) positive infinity, which is the only thing you can hope to be greater than the maximum floating point double value, with that value stored in rRemainderMinError (which is rather a misnomer).


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

09 Feb 2009, 1:00 pm

lau wrote:
You gave a code fragment. I critiqued that code fragment. Your "explanations" appeal mainly to things not shown in the code fragment.

I suggest you take all your comments above, and put them in your code as comments.



I didn't want to copy-and-past some 1500 lines.

lau wrote:
Returning "-1"? Don't you mean returning "-1.0"?


Yes - The actual of the method of matrix is the following:

Code:
double Matrix::GetError (SolutionVector   *pToCheck)
{
        double      rReturn      = 0.0,
                    rErrorCol,
                   *aTempToCheck = NULL;

        aTempToCheck = CreateTempAndCheck (pToCheck);
        if (aTempToCheck == NULL)
        {
                ErrorHandler::PrintErrorNonFatal ("<Matrix::GetError>");

                return (-1.0);
        }
        else
        {
                for (int iRow = 0; iRow < iCountRows; iRow++)
                {
                        rErrorCol = 0.0;

                        for (int iCol = 0; iCol < iCountCols; iCol++)
                                rErrorCol += aEntries [GetPointerElement (iRow, iCol)] * aTempToCheck [iCol];

                        rReturn += fabs (rErrorCol);
                }

                free (aTempToCheck);

                return rReturn;
        }
}


in which CreateTempAndCheck does not only extract the data from pToCheck, but also checks that the dimensions fit, that aEntries was set etc. So when it comes to the actual calculation, I do not need check for any bad surprises and can use here safely for-Loops.

lau wrote:
I do hope that you do not REALLY use std::numeric_limits<double>::max() the way you have suggested. Do you really rely on positive infinity as a return value? You must be certain that FP handling is set to use affine infinity, otherwise there will be an FP exception error when you come to compare your (nominally) positive infinity, which is the only thing you can hope to be greater than the maximum floating point double value, with that value stored in rRemainderMinError (which is rather a misnomer).


I am looking here for an all-lowest value, which is positive value by defintion. In the very first run rScore will have any value lower than max-double and this value will be written into rRemainderMinError. In further runs it will be checked against this value and will, if lower, overwrite rRemainderMinError. I just need a starting point high enough to find my lowest positive value.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

09 Feb 2009, 1:20 pm

Comments.

Lack of.

You seem to be acknowledging that your code fragment is unintelligible, unless it it read in the context of 1,500 other lines of code.

OK. I'm being brutal. However, I cannot stress the value of meaningful comments, as opposed to obscuring white space, enough.

Precisely how a piece of code does its work is rarely of any interest. Once it is working, it may never need to be looked at again.

If your comments say broadly what the code is intended to do, with maybe some justification for the algorithm chosen, and what any more obscure data is doing, then that should enable the maintainer to skip past the body with some confidence that that is what the code actually does.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

09 Feb 2009, 1:32 pm

t0 wrote:
lau wrote:
Why not:
Code:
fSuccess = (((DoSomething () == true) == true) == true);


I dunno, what exactly are you trying to say there? I don't understand why a person would communicate verbally in such a fashion and I don't think my AS is contributing to the misunderstanding. In my previous example, I was saying "if true is the result of DoSomething()" rather than "if DoSomething". You seem to be saying "if the result of DoSomething is true is true is true."


In a sense, you are right.

I am complaining about comparing boolean for equality to boolean to get a boolean result. Say it like that, and it sounds pretty obscure, no?

Dussel has misnamed his function, in my mind. His function is called "DoSomething", but that does not properly convey what it is.

It should be named more like "DoSomthingWorkedOK", as it is returning a boolean to indicate its success.

Hence I believe the code should read as:
if (DoSomethingWorkedOK()) { DoTheNextBitOfStuff(); ... }

Choosing to compare the perfectly good boolean return value to a boolean constant, it then would read as:
if (DoSomethingWorkedOK() == true) { DoTheNextBitOfStuff(); ... }

I'd say that the former conveys exactly what is happening. The later is just stilted computerese.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

09 Feb 2009, 1:48 pm

lau wrote:
Comments.

Lack of.

You seem to be acknowledging that your code fragment is unintelligible, unless it it read in the context of 1,500 other lines of code.

OK. I'm being brutal. However, I cannot stress the value of meaningful comments, as opposed to obscuring white space, enough.

Precisely how a piece of code does its work is rarely of any interest. Once it is working, it may never need to be looked at again.

If your comments say broadly what the code is intended to do, with maybe some justification for the algorithm chosen, and what any more obscure data is doing, then that should enable the maintainer to skip past the body with some confidence that that is what the code actually does.


When I am in a object-oriented context the really important part is the definition of the public methods. How I do handle internally in my class the results (as a vector-template, as a array, as I do, or else) is not of real interest, when the class has been set up properly. as class of mine has often not more than 10 public methods, and anything which reminds on data is private.

BTW: This is small project for my hobby. When I write in professional environment, I write an external documentation in which I go into detail how and why I did something and discuss in length the arguments in favour and against certain solutions or provide lengthy tables with possible values, return values and cross-references. Such documentation easily reached some 100s pages of small print and grow normally out of the design notices I collect during the development. When I write code for my own I remember very well what I wrote and why I wrote it.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

09 Feb 2009, 2:07 pm

Dussel wrote:
... When I write code for my own I remember very well what I wrote and why I wrote it.

So why offer up a code fragment that you knew would be unintelligible, as if it exemplified good practice, maintainable code?


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

09 Feb 2009, 3:20 pm

lau wrote:
Dussel wrote:
... When I write code for my own I remember very well what I wrote and why I wrote it.

So why offer up a code fragment that you knew would be unintelligible, as if it exemplified good practice, maintainable code?


I thought it was obvious that the necessary check-up, control flows etc. would be already done and that the not-declared variables are members of the class. One of the main benefits of object-orientation is to hide such functionalities and protect ("private") those from any call from outside the class (even this concept is in C++ a bit weak - "friend"/"protected"); it was just outside my mind that anyone even would think about this.

Therefore I was surprised about your comments, even I see now, why you raised those.



Eggman
Veteran
Veteran

User avatar

Joined: 17 Jul 2008
Gender: Male
Posts: 4,676

09 Feb 2009, 3:57 pm

No. Tying such qualities to programming languages does not make sense


_________________
Pwning the threads with my mad 1337 skillz.


Relicanth7
Veteran
Veteran

User avatar

Joined: 30 Sep 2007
Age: 31
Gender: Male
Posts: 1,896
Location: 'Murika... (Insert explicit word here) yeah!

09 Feb 2009, 7:07 pm

Eggman wrote:
No. Tying such qualities to programming languages does not make sense


C++ Java or other OOPs could be consitered aspieish due to the fact they are dealing with spesific types of atributes of programing... :?


_________________
~Aaron, the professional doormat.


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

09 Feb 2009, 11:41 pm

Eggman wrote:
No. Tying such qualities to programming languages does not make sense


It makes sense: If you ever debugged the 10th complex list in C in a program when any pointer-stew raised you happy to have a cover or even a template which you need to establish just ones.



t0
Veteran
Veteran

User avatar

Joined: 23 Mar 2008
Age: 50
Gender: Male
Posts: 726
Location: The 4 Corners of the 4th Dimension

10 Feb 2009, 12:24 pm

Quote:
I am complaining about comparing boolean for equality to boolean to get a boolean result. Say it like that, and it sounds pretty obscure, no?


I think I prefer to compare the results of functions (even in the case where they return boolen values) as a defensive programming mechanism. If someone else changes the function to return a different type and misses one or more of the references, hopefully my compiler will generator a warning indicating such.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

10 Feb 2009, 12:50 pm

t0 wrote:
Quote:
I am complaining about comparing boolean for equality to boolean to get a boolean result. Say it like that, and it sounds pretty obscure, no?


I think I prefer to compare the results of functions (even in the case where they return boolen values) as a defensive programming mechanism. If someone else changes the function to return a different type and misses one or more of the references, hopefully my compiler will generator a warning indicating such.

Yes - the condition in an "if" is required to be boolean (in any sensible language). I prefer to make it boolean, rather than have an error reported.

The problem with a language that does NOT require a condition to be a true boolean type, is that people introduce horribly difficult bugs, by doing what you suggest:

Code:
#define TRUE 1

if (SillyCFunction() == TRUE) { NeverDoThis(); }


This, where SillyCFunction is perfectly within its rights to return zero for false, and any other value for true. That is what a conditional will test for, by definition of the language.

Arbitrarily adding a layer of text that you feel "looks better" is just making the code more verbose, less clear, and prone to an additional set of bugs.

The only valid way of coding the above sort of C thing would be:
Code:
#define FALSE (0)

if (SillyCFunction() != FALSE) { DoThisWentTrue(); }
I still wouldn't use the above.

If I really have to have a FALSE constant, and even a TRUE one, I will use:
Code:
#define FALSE (0 != 0)
#define TRUE (!FALSE)

which is as language portable as it can be.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

10 Feb 2009, 12:50 pm

t0 wrote:
Quote:
I am complaining about comparing boolean for equality to boolean to get a boolean result. Say it like that, and it sounds pretty obscure, no?


I think I prefer to compare the results of functions (even in the case where they return boolen values) as a defensive programming mechanism. If someone else changes the function to return a different type and misses one or more of the references, hopefully my compiler will generator a warning indicating such.


With "real live" projects you often have to include headers (and libraries) from other projects. I found, especially if pure C-headers are included (or legacy code, slightly covered in classes), stuff like:

Code:
#define bool short
#define true 1  // sic!
#define false (-1)  // sic!


If you can't rewrite the old code, you are better off with an explicit check.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 75
Gender: Male
Posts: 9,619
Location: Somerset UK

10 Feb 2009, 1:05 pm

Dussel wrote:
Code:
#define bool short
#define true 1  // sic!
#define false (-1)  // sic!


If you can't rewrite the old code, you are better off with an explicit check.


Technically, the above "#define" for "true" is correct. K&R does indeed specify that the value of a boolean test, assigned to a variable, will be zero, for false, and unity, for true.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


0_equals_true
Veteran
Veteran

User avatar

Joined: 5 Apr 2007
Age: 41
Gender: Male
Posts: 11,038
Location: London

10 Feb 2009, 1:24 pm

I prefer the ruby way, it makes sense, and you don't use silly functions/statements to see if something is 'empty' or set. 0 evaluates true being from numerical class and meaningful in that form, just like the string '0' would evaluate to true. Only nil and false evaluate to false.

0 was invented by the Babylonians as a placeholder in their early positional number system. The Indians expanded on this in their arithmetic. What it means it dependent on context. Equating it to nil is not always appropriate.

Nil is not the same as undefined in other languages. Nil signifies emptiness. Whereas undefined means it hasn’t been defined.



t0
Veteran
Veteran

User avatar

Joined: 23 Mar 2008
Age: 50
Gender: Male
Posts: 726
Location: The 4 Corners of the 4th Dimension

10 Feb 2009, 2:33 pm

lau wrote:
The problem with a language that does NOT require a condition to be a true boolean type, is that people introduce horribly difficult bugs, by doing what you suggest:

Code:
#define TRUE 1

if (SillyCFunction() == TRUE) { NeverDoThis(); }


This, where SillyCFunction is perfectly within its rights to return zero for false, and any other value for true. That is what a conditional will test for, by definition of the language.


I'm not talking about making up constants (or macros) to compare. I'm talking about using predefined constants based on the documentation of a function. If a function is defined as returning 0 for failure and non-zero for success, you should only compare the result to 0. Not TRUE or FALSE or S_OK or some other constant you've come up with. If the docs say to compare it with TRUE or FALSE, then do so.

I would also suggest that programmers writing functions define and return constants rather than things like "!TRUE" or "!FALSE". In many ways I like the HRESULT that COM uses. It has defined constants for success and failure conditions and defined macros for determining what a particular value means. It's also extendable so that programmers can add their own values.

Quote:
Arbitrarily adding a layer of text that you feel "looks better" is just making the code more verbose, less clear, and prone to an additional set of bugs.


We'll just have to disagree on this one. I think it makes the intent of the programmer clearer and can reduce bugs.