Evaluating string

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?


1 Like

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.

1 Like

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.

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