Evaluating string

Evaluating string
0

#1

It seems eval(string) works fine for my operations, but I read online that eval(string) is bad practice for websites/web apps. I wanted another person’s opinion on this and was wondering if I should change it?

Thanks


#2

Executing eval on user-inputted strings is bad because sooner or later someone will find (or stumble upon) a way to eval something unexpected (and potentially disastrous) :wink:

With the calculator, though, there is not much scope for a disaster, really. So on one hand, I wouldn’t worry too much about it. On the other, I was thinking about it myself (inspired by other campers) and I suppose trying to make the calculator work without eval could be interesting.


#3

I’ll finish all the other projects before thinking of changing the work then. I heard some people just use a data structure to keep all the numbers and remove one number at a time while parsing it to an integer. There is a lot of ways to do it though, Thanks for giving me the info on why its dangerous to use it.


#4

+1 for the shunting yard algorithm. It’s fun to implement :smiley: