
-----------------------------------
EDEN-E
Mon Apr 19, 2004 8:13 pm

Short Way of Writing Code
-----------------------------------
1.
When we use loop statement, we often use some variable to count for some reason.


   var counter : int
   counter := 0
   loop
      counter := counter + 1
      put "Hi!"
      exit when counter = 3
   end loop



The key for counter is "counter := counter + 1", which add 1 to itself.
However, it seems useless to write counter two times.
The short way for this code is

   counter += 1



This way can be applied to substraction, mutiplication, or division.
Also to real type, string type, etc

   makrs -= 1.5

   sentence += "word"

   power *= 2



What happens if you put more than a term on right side?

   compsci += 5 + 1



I hope you know already, above code are exactly same as compsci := compsci + 5 + 1



2.
The next tip is about declaration and assignment of variable.
Do you think following code are efficient?

   var counter : int
   counter := 0



Maybe NOT.
You can make this two steps into one step.

   var counter : int := 0



But there is still one thing that you really don't need to put.
Counter was declared as a integer type and assign to 0 at the same time.
Because compiler know 0 is integer, you really don't need to say "counter is a integer type"

   var counter := 0



Of course, you can declare any types of variable like this.

   var counter := 0
   var word := "Hello"
   var check := true





3.
The last tip is for the use of boolean type in condition.


   var check := true
   if check = true then
      put "check is true"
   end if



Because boolean data can have true or false, you don't need to put "= 
true"

   if check then



If you want to say "check = false", which means not true, put not infront of check.

   if not check then





Bonus Tip
When you use "not=", have you thought that it looks ugly or odd for programming language?
Of course, there are another way to say  "not=".


   if counter ~= 3

   if ~check then




.

-----------------------------------
AsianSensation
Mon Apr 19, 2004 9:27 pm


-----------------------------------
nice, I like the ~=. I would have thought that turing would have used !=, considering C++ uses it.

and another thing, to declare a real type variable and set it to 0, do this

var num := 0.0

anyways, +10 bits

-----------------------------------
Catalyst
Mon Apr 19, 2004 9:33 pm


-----------------------------------
other notes
 

function FooBar:real
result 0
end FooBar

procedure FooTank
end FooTank


can shortened to



fcn FooBar:real
result 0
end FooBar

proc FooTank
end FooTank


-----------------------------------
EDEN-E
Mon Apr 19, 2004 10:17 pm


-----------------------------------
nice, I like the ~=. I would have thought that turing would have used !=, considering C++ uses it.

yea, most langueges use != for not equal...
turing uses := rather than =

i don't know why holt soft made like this...

hmm... i think... holt soft wanted something differen.. like "Canada" haha

-----------------------------------
Tony
Mon Apr 19, 2004 10:32 pm


-----------------------------------
well turing also uses = rather than == :lol: 

but turing's main advantage is their simple syntax that students supposedly understand better... so who knows :roll:

-----------------------------------
EDEN-E
Mon Apr 19, 2004 10:42 pm


-----------------------------------
turing's main advantage is their simple syntax that students supposedly understand better... so who knows :roll:

turing syntax makes me mad!
i had learned GW-basic, Q-basic, turboC, C++, ...
and... now i am learning turing (for school compsci)

for i : 1 .. 10 so funny

and... there's no something like i++...  :evil: 
no predeclaration ...  :x 
which are really useful... hmm... 

all programming languages are similar...
it does not take long time to learn another language, if you learned another language..

but turing is so different.....

besides,,, i forgot so many commands for c++... i should look up the book again.


arararkajlsdkfjahfalsdj;fkj

-----------------------------------
Catalyst
Mon Apr 19, 2004 10:59 pm


-----------------------------------
turing has a lot of advanced features for a learning language

-----------------------------------
gamer
Wed Apr 21, 2004 5:32 pm


-----------------------------------
yea man i agree....btw why do some people say turin sucks?

-----------------------------------
Catalyst
Wed Apr 21, 2004 5:41 pm


-----------------------------------
while it has many nice features for a learning laguage, some of its syntax can confuse you once u move up to other languages

for example:
   in c,c++ or java using = to compare things actually assigns them (u have to use ==)

Also many of the built it routines and such are slow and theres no way to try to fix them

-----------------------------------
gamer
Wed Apr 21, 2004 5:58 pm


-----------------------------------
ok i think turing is for beginner programmer, but why wont schools just starting teach c++ or java in the beginning?? it shouldnt be any harder, since students are new to programmin anyway. this way, students can be much beter programmers later on

-----------------------------------
Paul
Wed Apr 21, 2004 6:35 pm


-----------------------------------
ok, failure rate at my school of ppl who take compsci: 10%
according to my Java experience,
failure rate if my school taught java from the start: 45%

-----------------------------------
Catalyst
Wed Apr 21, 2004 6:45 pm


-----------------------------------
failure rate at my school ~10%

failure rate if no one cheated ~70%  :lol: 


The school system seems to have the philosophy (which seems correct) that one of the major hurdles to learning programming is getting comfortable and understanding the syntax. Turing has a very readable syntax almost reading like pseudocode which makes it nice for new programmers.

-----------------------------------
gamer
Wed Apr 21, 2004 7:34 pm


-----------------------------------
oic...dats why
but still, prsoanlly i would hav rather began with java or sumthin at first, cuz if u began with turing n decided to learn java or c++ later on, i think u'
ll get confused easily n mess up

-----------------------------------
AsianSensation
Wed Apr 21, 2004 9:01 pm


-----------------------------------
well, learning Java and C with classes requires a new way of thinking. Java is all Object Oriented Programming, and teaching someone that doesn't even have a grasp of the simple concepts OOP will lead them to be even more confused then before.

-----------------------------------
Catalyst
Wed Apr 21, 2004 9:05 pm


-----------------------------------
both languages can be taught w/o their OOP (java is a bit tricky to do w/o oop tho)

-----------------------------------
gamer
Wed Apr 21, 2004 9:24 pm


-----------------------------------
oic...owell im still stuck with turing for now

-----------------------------------
MyPistolsIn3D
Thu Apr 29, 2004 3:37 pm


-----------------------------------
Well, at my school it goes from classic turing to oot, then they teach java in grade 12. without doing the turing first, java is harder.

-----------------------------------
wtd
Fri Jul 16, 2004 8:46 pm


-----------------------------------
Plenty of other languages use := for assignment, though the term also used sometimes is "binding", as in binding a name to an object or value.

Since = makes much more sense that == for evaluating constants, the typical approach is to use something else for assignment/binding, which is why := is used by many programming languages.

As for ~= vs. !=, there is history to support that as well.  Typically ~ in low-level (assembly) languages is used to represent a "not" operation.  In languages without operators like += and -= (one example would be Eiffel, and if memory serves, Fortran90), /= is sometimes used to represent inequality.
