
Re: Creating Beautiful Code
Object Oriented Programming is generally cleaner. It is actually not too difficult comparing to "Procedural Programming". In fact, a lot of people thinks OOP is easier. OOP promotes code reuse by using inheritance. Language is irrelevant whether you have multi-core or not. By "multi-core", I assume you really meant "multi-tasking" programming. You can do multi-tasking programming regardless of how many cores you have or whether you use OOP or Procedural Programming language. The main difference between OOP and Procedural Programming is about objects. In Procedural Programming language, functions and data are separate. You always call a function and pass the data to it for processing. But for OOP, data is encapsulated inside of an object along with "methods" (same thing as functions) that process the data. If you are fluent enough, you can do Object Programming with Procedural Programming language. For example, we have developed a RobotC library simulating Object Programming. So instead of Object.Method(parms), we do Function(Object, params).
Regarding your code, if you partition your code into subsystems, you can easily see how the code can be "refactored" into functions such as the following:
BTW, the usercontrol function above is actually a "cooperative multi-tasking" scheduler. Imagine each subsystem is a task, the loop is doing a round-robin scheduling of each task. The only thing about "cooperative multi-tasking" is that each "task" (or subsystem) must not block progress. In other words, there should not be any wait loops or wait1Msec() type of statements in each task. That's what cooperative means. If any task contains wait loops or wait statement, it will prevent other tasks from running.