|
|
|
|
|
by philwelch
6155 days ago
|
|
"A lot of people use languages where recursion is unusual (i.e. NOT Lisp). Even a senior developer (especially of something like PHP) might not recall this, not having actually written a recursive function for years." There are tons of languages that support recursion. Whether or not you use it is a function of the problem, not the language. (I'm not counting tail recursion since I consider tail recursion to be a functional way of expressing iteration.) "Representing a car as an object: A lot of software people don't know hardware, so the confounding part might be recalling various attributes of cars and how they relate to each other." Well, if I was given this question in an interview, I would ask, "are we building a CAD program or a car-racing game"? CAD programs (I've never written one) would probably have a CADObject class for all drafted objects that the car parts and the car itself would inherit from, and you'd have to discuss not only what was in the car but where it was connected, so just saying that it's a composition of "engine, body, brakes, air filter, etc." would be insufficient. A car-racing game would just have a car object with a shape, performance characteristics, and be able to hold states for its physical motion at a given time, as well as being able to take messages/method calls for things like "pressing the turbo button" or "emergency brake" or "shoot a missile" (depending on the racing game). You can build an entirely sensible object model for a car and be totally wrong if you don't know what you're building it for. |
|
Obviously. But I don't remember ever writing a recursive function in PHP for a website.