Timeline for Martingale Betting Simulator
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 22, 2020 at 0:41 | comment | added | user985366 | Nice, looks a lot better. | |
Sep 22, 2020 at 0:28 | comment | added | Stephen Williams | I think I figured out what you were telling me. I ditched the class, defined variables in a main function, and used functions to pass in values. This is the refactored code pastebin.com/X6RZCAtr . I'm sure there's still plenty of room for improvement, but I hope this is better. | |
Sep 16, 2020 at 0:39 | comment | added | user985366 | The problem with the program you posted on SO is that you're not passing parameters into your functions, and in some cases not returning values either. If you did, you wouldn't need any globals. If you post that program here on codereview, I'll suggest some changes. | |
Sep 16, 2020 at 0:30 | comment | added | user985366 |
Also, from the suggestions to the StackOverflow post, I agree that it would be good to create a main function and keep the variables ("state") inside, while using other functions to calculate intermediate values as needed. Values will be passed between functions, but you shouldn't need globals.
|
|
Sep 16, 2020 at 0:28 | comment | added | user985366 |
Found your original post. You defined running_profit = running_total - starting_funds and answers/comments explained why that didn't work. It does not create a dependency, and the solution is like you did in this code, to create a function for it instead so that it is calculated each time you need it.
|
|
Sep 16, 2020 at 0:20 | comment | added | user985366 | I don't understand the question, and I don't see the problem. Perhaps it would help to see the version you wrote without a class. In the current program, the class is only initialised once, all the variables are "effectively global" within the object itself, and all the code runs within that single object. So encapsulating all of this within an object does nothing really. It just adds a lot of code. | |
Sep 15, 2020 at 23:45 | comment | added | Stephen Williams | Thank you for the feedback. I originally wrote this script without a class and was told by a user on Stack Overflow that I should implement one. I was using the globals everywhere in almost every function to keep track of running totals which would otherwise be reset by the function every time it ran. What would be a good solution for that problem? | |
Sep 15, 2020 at 20:51 | history | answered | user985366 | CC BY-SA 4.0 |