7 ms·
> As a result, solutions using strings are disallowed on problem sets and quizzes until they are taught. However, the few students who have prior Python program
by svnpenn 7y ago
> As a result, solutions using strings are disallowed on problem sets and quizzes
until they are taught. However, the few students who have prior Python
programming experience may be tempted to find digit length without loops using a
variant of the following (for our purposes) invalid solution.
Wow. this is one of the reasons I hated school. No programmatic reason what
given for why a string solution couldnt be used, only an arbitrary reason. Here
students may have knowledge from self teaching or whatever, but they are
unallowed to use that knowledge because "reasons".
To any teacher that thinks its a good idea to punish students for thinking
outside the box: shame on you. All youre going to end up doing is crushing
enthusiasm and/or creating drones. Please dont.
- ianai 7y agoAgreed. I think you could even argue that string manipulation is even more common than uses of math.ceil, floor, the floor division operator (//), and so on. I love math, but this is a programming class. This also fails my personal rule to always need to have a reason to do something mean - like failing someone on a problem, and no reason to do something nice - like saying it’s fine since it works.
- kevin_thibedeau 7y ago> I love math, but this is a programming class. Sometimes you actually have to do arithmetic when programming. It's useful to teach people these sort of things so they don't cook up half baked solutions in the future.
- moron4hire 7y agoDrastically depends on the kind of problems you're working on.
- jstrieb 7y agoIt's a programming class where "algorithmic thinking" (and therefore, in my opinion, some amount of math) is one of the course objectives. Since the discussion takes place in a low-pressure, guided group lesson, students will certainly not be penalized for suggesting the string method in that setting. Also, students trying to use strings on homework will fail tests in the linter and autograder before they finally submit, so they will have plenty of opportunity to fix their mistake before receiving a grade on their work.
- userbinator 7y agoStrings are disallowed because they are not necessary for this problem and although the solution is shorter, is far more inefficient; it also doesn't demonstrate the algorithmic thinking that the course is obviously trying to teach. I've taught CS courses before, and have seen plenty of self-proclaimed self-taught know-it-alls who seem to be more stackoverflow-copy-pasters than anything else.
- svnpenn 7y ago> Strings are disallowed because they are not necessary for this problem the division examples are not necessary either, thats the point. you can solve it different ways, that doesnt mean one way is not necessary, it just means its different. one may be faster, one may be more readable. If you dont allow different solutions you cant explore the tradeoffs between them.
- jstrieb 7y agoI note that the solution is invalid at the bottom of my post, but it is worth mentioning that I know all of the students in the group session when I teach this problem, and I am familiar with their background. If I know that a student has prior Python experience, I will discuss the string solution with them, but let them know not to use it in their homework until strings have been covered in class. In this case, even though the solution is disallowed for grading purposes, there is an opportunity to discuss it during the lesson.
- tzs 7y agoGenerally, the purposes of the exercises in a class is to reinforce the material that has been taught up to that point and to demonstrate that the student can use it. For example, if early in an elementary number theory class the student is asked to prove that there are in infinite number of primes of the form 4n+3, a solution that just invokes Dirichlet's theorem on primes in arithmetic progressions would probably not be acceptable. That approach does work to show that there are an infinite number of 4n+3 primes, but completely fails to show that that the student understood the material actually taught in class. It's the exact same thing with the digit counting problem. Solving it by just invoking the built in string length function does little to demonstrate that the student understands the material taught so far.
- wfleming 7y agoBecause I am a smart-ass, I did something like this in college. There was an intro course in MATLAB my freshman year, but I'd been programming for several years at that point so I found it too basic to hold my interest. In one of our early labs, we were told to implement a function that calculated a Fibonacci number. I figured that sounded like something MATLAB probably had in its stdlib, and it did, so I wrote a 1 liner and called over a TA to approve my work. Thankfully this TA agreed with you (as do I). He said it looked good, and I think that's the shortest lab I ever had.
- em-bee 7y agoif i was the TA i would have said: "congratulations, for you have not learned anything new" personally, when something is to basic to hold my interest, i try to find ways to make it more challenging.
- Retric 7y agoI personally learned quite a bit in a similar situation. In an operating systems class we had a little project to create a command line calculator in C, with the added hoop of using x86 ASM for all control flow and calculations. As this was not a programming class we had a very brief overview of the very basics needed to get this done. I assumed using floating point arithmetic would make this easier, but knew that was not part of the early spec, so I asked the professor in class what version of x86 and he said pentium 1. I then found and read intel’s documentation for the first generation Pentium. Which completely changed my mental model of CPU’s. Honestly, it was probably the closest collage assignment to how real world coding works and much more useful long term than just implementing some simple algorithms by hand.
- wfleming 7y agoI was quite comfortable with writing the Fibonacci function. Writing that would have hardly taken me any longer and would not have taught me anything either. The thing I did learn, and which I think has paid more dividends in my career than knowing the definition of the Fibonacci sequence, is that knowing your tools well can save you time and effort and reduce the amount of your own code you need to maintain and put effort into.
- em-bee 7y agoworking with contraints (don't use loops, or don't use the string function) is a learning tool. don't dismiss it just because it prevents your clever trick from working.
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- MrStonedOne 7y agoConstraints are fine. Blocking off a generic "anything you haven't been taught yet" is a hellfire of ambiguous egg shells. Strictly speaking you might not have been taught to use division with loops. Maybe you haven't been taught about the log10 function, or you have but you haven't been taught about combining the log10 function with the round/ceil functions, are you sure you were taught about putting if's before these exact functions? The issue is every programming question requires by its very nature that you use something you haven't been taught to solve it. So you have to know what the teacher counts as acceptable vs unacceptable, and this comes into weird edge cases where the logic behind why something would be considered part of the "you must be taught first" category vs the "you are to assume figuring this out is part of the question" category requires knowing an overview of how to teach computer science, something the students would not have. I once got points taken off for using a recursive function as part of my solution because that wasn't taught until the next quarter. I didn't know the language before, nor did I have much experience with recursive functions as a formal concept. We knew how to make functions, call functions, do loops, and even do gotos. I didn't even know at that time that recursive functions were a special thing that had to be taught to me, it just came to me as the way to solve the problem.
- em-bee 7y agoi agree, constraints and "anything you haven't been taught yet" are two different things. constraints should be spelled out explicitly. The issue is every programming question requires by its very nature that you use something you haven't been taught to solve it that, i don't agree with. it's entirely possible to state programming questions in such a way that they only require things you have already been taught. (in its simplest form "being taught" means "being told about". most (if not all) freecodecamp exercises work like that.
- hechang1997 7y agoI don't know about this. This feels like cheating rather than thinking outside of the box. Like when you ask a student to implement a vector in C++, instead of writing the code the student makes a wrapper around std::vector. Internally, `str` probably also use some equivalent of the naive solution implemented somewhere to convert a integer to its decimal string.
- kadoban 7y agoUsing math.log10 seems at least as cheating to me. (though to be clear, I'd accept both if it were me)
- _bxg1 7y agoThis isn't thinking outside the box, it's an incredibly obvious way to avoid using your brain. There's nothing wrong with creating constraints on a problem, as long as those are clearly defined. Presumably the OP didn't neglect to mention that strings were disallowed, and then just fail anyone who happened to use them.
- lilyball 7y ago> No programmatic reason what given for why a string solution couldnt be used, only an arbitrary reason The entire problem is arbitrary. It's not a real-world problem looking for a solution. It's a programming exercise.
- rurounijones 7y agoI think it is more of a math exercise solved via programming. Which is somehing I am not particularly fond of. These crop up all the time in those online programming challenge things. They are usually maths problems (e.g. Find the combined area of two partially intersecting squares based on their coordinates of a,b,c,d and w,x,y,z) where the solution is done via programming but most of the work is, in my opinion, figuring out the maths which is testing for the wrong thing.
- raegis 7y agoMany things people consider "programming" but not mathematics are things we actually study in mathematics classes. They're just unaware.
- NightMKoder 7y agoThis particular problem (number of digits in a number) is actually monumentally important for performance reasons for e.g. json generation. See https://m.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920/ https://m.facebook.com/notes/facebook-engineering/three-opti... for details. That said, I do agree that as stated the problem is a toy. The problem statement could at least motivate the lack of string operations - i.e. pretend you’re the language designer and you’re tasked with implementing str(int) in C. Just saying “don’t do that” isn’t helpful. Gaining an understanding that nothing is magical is useful though.
- FabHK 7y agoThat link has a very insightful discussion (and incidentally provides a nice fast correct solution, and use case, for the initial problem!).
- atoav 7y agoI think this is a communications issue. If you ask them to solve it and then they clearly did, but you then say: “bUt yOu dIDn’T SoLvE iT tHe RiGht wAy”, then it is clearly your fault. I think if you tell stuff like this upfront it is totally acceptable: “Reduce the number of digits in a given float without converting it to a String”. Even students with previous knowledge could take this as a challenge where they learn something.
- hoseja 7y agoPrecisely. It was the first solution I came up with after reading the title. It's perfect in that all the subtleties are already handled by the language. Digit length of base10 numbers isn't really a logic/math/computer problem, it's a string and writing convention problem.
- AlecSchueler 7y agoThis problem is a funny one for me and gives me real nostalgia, back to about ten years ago when I was learning to program. I'd just picked up python and was having so much fun going through the project Euler problems. I can't remember which question it was for but we had to know the length of an integer. At that point I hadn't learnt about type conversion so had to implement it the way the author wants his students to do it. I remember fondly as well that I hadn't learnt about the modulo operator and had to implement that by myself as well. I couldn't believe it when I got the answer and progressed to the forum where others shared their answers and they were doing it on one line with %! Good times!
- tomxor 7y agoIt's also not great advice to be so ridgid in this case... Having written numerical grading code, I learned the hard way that log10 based methods of counting SF is a very bad idea (fp errors occur toward but not at word precision limit) counting string length with some solid regex for extracting integer fraction and exponent parts on the other hand can handle any input precision.
- jstrieb 7y agoThis problem is designed more in the spirit of teaching the algorithmic thinking side of the course objectives than the Python side. If you prefer, you can view the problem restrictions as a means to encourage students to develop a more general algorithm for solving the problem, rather than a programmatic implementation specific to Python. Hopefully this makes them seem less arbitrary.
- MrStonedOne 7y agoThere is also the issue that they may not know that the thing isn't "taught" yet because they don't know its a "thing". I once got points taken off for using a recursive function as part of my solution. I didn't know the language before, nor did I have much experience with recursive functions as a formal concept. I didn't even know at that time that recursive functions were a special thing that had to be taught to me.
- surfsvammel 7y agoIn school the goal isn’t to solve the problem, but to learn something in the process of solving that problem. Thinking outside the box is of course valuable, but the teachers have specific concept they want to teach and constraints like that help them accomplish that. When it comes to tests, it’s not as easy. At tests it’s is more about solving the actual problem, but one could still argue that the test is meant to test how well one has learned what was thought, not to solve the problem. I think this is totally fair in this case.