[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [computer-go] Re: which programming language is better



Compgo123@xxxxxxxxxxxxxxxxx wrote:

Recently I got some new ideas and decided to re-write my program. So this subject has some meaning to me. My experience tells me that the easiness to debug a program is of great importance. The most often met problems are the memory leak or illegal memory reference.
I agree with all of that, but I disagree with the solution.

So there should be a convenient way to check memory leak and to debug.
To have no memory leak, there is a better solution , there is a lot of language designed to avoid them. Did you already try Pyhon or Ruby? In my experience, they are easier to use than C. To a C programmer, I would give you the advice to use Python wich is the more close to C language.
Moreover, is an easy way for reuse C code.

Xavier
Anyone as the language he prefer, but
programmer life would be easier, if every go programmer
use only one language wich would fit all our needs.
I'm sure it's not Python, maybe we should design it ourselves.

--
After that, just an example of use of Python, read it if you want.
My example is the gtp protocol managing . He just use one method of 31 lignes.
To manage a new gtp command I just have to add the corresponding
method. The interface specification of a gtp command is:
- begin with do_
- waiting for a variable number of arguments
- return a response as a string without trailing carriage return
- set self.error to True if the return message is an error message

My opininion is, even without speaking of variable declaration wich is
not very usefull here, I don't know any language, where I can do that
without writting extra code.
My personal exerience is that piece of code work at the first time
withour syntax error or bug.

--
#python way to manage gtp.
# I think the code is clear, but if you have any question ask me
# the gtp manager
def process(self,line):
self.log("cmd: "+line)
self.error = False
args = line.split()
if args[0].isdigit():
cmd_id = args[0]
args = args[1:]
else:
cmd_id = ''
command_name = args[0]
args = args[1:]
mname = 'do_' + command_name
if not hasattr(self, mname):
self.log("pas trouve "+ mname)
self.error = True
reponse = "unknown command"
else: method = getattr(self, mname)
reponse = method(args)

if self.error:
reponse_type = '?'
else:
reponse_type = '='
reponse = reponse_type + cmd_id + " "+ reponse
#print "rep: '" + "'\n"
self.log("rep: "+reponse)
return reponse #create a new gtp function, is quite easy
def do_boardsize(self,args):
self.board_size = int(args[0])
# here it's just technical stuff, nothing to do with gtp
self.all_places = list(double_loop(1,self.board_size))
return ""

--
To conclude, I would say that I did not change one line of my
code, just hadding the comments.
All that I show is code I writted the first time, without
thinking of clarity. However it's clear, don't you think it's wonderfull?

_______________________________________________
computer-go mailing list
computer-go@xxxxxxxxxxxxxxxxx
http://www.computer-go.org/mailman/listinfo/computer-go/