Some Exercises

F

feivue

1. In Java, intergers can be assigned to real variales, but not vice versa.
What design principle does this violate? In C, this restriction does not
exist. What design principle does this violate?

2. C use the semicolon as a statement terminator, but also allows a
statement to be empty(that is, consisting of only a semicolon), so that the
following is a legal C program:

main() {
;;;;;;;;;
return 0;
}

Discuss the advantages and disadvantages of this.
 
M

Mike Wahler

feivue said:
1. In Java, intergers can be assigned to real variales, but not vice versa.
What design principle does this violate? In C, this restriction does not
exist. What design principle does this violate?

2. C use the semicolon as a statement terminator, but also allows a
statement to be empty(that is, consisting of only a semicolon), so that the
following is a legal C program:

main() {
;;;;;;;;;
return 0;
}

Discuss the advantages and disadvantages of this.

OK let's discuss. You start.

-Mike
 
E

Erik

1. In Java, intergers can be assigned to real variales, but not vice
versa.
False, what is true is that Java requires an explicit cast because you may
lose
precision
What design principle does this violate? In C, this restriction does not
exist. What design principle does this violate?

2. C use the semicolon as a statement terminator, but also allows a
statement to be empty(that is, consisting of only a semicolon), so that the
following is a legal C program:

main() {
;;;;;;;;;
return 0;
}

Discuss the advantages and disadvantages of this.

Pointless question.

If I were you, I'd skip the class and learn C or C++ (which I guess is the
class topic since you posted here) from a book instead.

/ Erik
 
O

osmium

Erik said:
Pointless question.

If I were you, I'd skip the class and learn C or C++ (which I guess is the
class topic since you posted here) from a book instead.

Obviously, I didn't consider it pointless. I thought it was much too
difficult for an introductory class; which is why I supplied some thoughts
on the subject. It is absurd to think that after a few weeks of use a
neophyte could answer question more properly addressed to a designer of
languages. IMO this is a witches brew which touches on, at least
tangentially, the dangling else problem.
 
R

Ron Natalie

feivue said:
2. C use the semicolon as a statement terminator, but also allows a
statement to be empty(that is, consisting of only a semicolon), so that the
following is a legal C program:

main() {
;;;;;;;;;
return 0;
}

The above is not a legal C program. Functions must have explicit return types.
 
O

osmium

Ron said:
The above is not a legal C program. Functions must have explicit return
types.

Maybe he will get some extra credit if he mentions that to the instructor.
:-(
 
N

Noah Roberts

osmium said:
Ron Natalie writes:



types.

Maybe he will get some extra credit if he mentions that to the instructor.
:-(

I have found that instructors that teach programming languages
incorrectly do not like being corrected. For instance, in my C language
course one of the questions on the midterm was "find all the errors"; I
crossed out void main and wrote int. He marked me wrong. "I'm not
worried about ANSI compliance," is a quote often attributed to these
types as well as, "Don't enter any values that make your program fail,"
in other words - don't worry about input integrity checks! They also
don't like being told that their code doesn't work on all compilers:
"fflush(stdin);" works on many, but fails on many as well - they usually
don't want to hear things like this; if it works in the compiler they
are using to teach the course then it must be valid code - who cares if
much of the world, including the students, use something else.

You may have to purposfully write buggy code to pass a course like that.

So, in my opinion, you might want to think twice about telling the
proffessor he is wrong. If you crush an ego he may crush your grade,
its unfortunately the way things are sometimes.

NR
 
O

osmium

Noah Roberts writes"
I have found that instructors that teach programming languages
incorrectly do not like being corrected. For instance, in my C language
course one of the questions on the midterm was "find all the errors"; I
crossed out void main and wrote int. He marked me wrong. "I'm not
worried about ANSI compliance," is a quote often attributed to these
types as well as, "Don't enter any values that make your program fail,"
in other words - don't worry about input integrity checks! They also
don't like being told that their code doesn't work on all compilers:
"fflush(stdin);" works on many, but fails on many as well - they usually
don't want to hear things like this; if it works in the compiler they
are using to teach the course then it must be valid code - who cares if
much of the world, including the students, use something else.

You may have to purposfully write buggy code to pass a course like that.

So, in my opinion, you might want to think twice about telling the
proffessor he is wrong. If you crush an ego he may crush your grade,
its unfortunately the way things are sometimes.

NR

Oh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top