thewhitetulip / build-app-with-python-antitextbook

Aims to teach Python3 by example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues

TonyFlury opened this issue · comments

I applaud you for trying to do this - but I have noted one or more issues :

  • Variables page - the id function does not return the address - it returns the object identifier. It is not intended to be nor should it be implied that it is the address.
  • Variables Page - a nit pick here but strictly speaking the variable doesn't have a type. The value has a type and the name simply points to an object which has a value. In Python it is dynamic typing, so you can assign an integer object to a name, and two lines later assign a string object to the same name. Talking about objects (rather than 'memory') is important because only some objects in Python are mutable, and some aren't : adding something to a list will change the list - adding a value to a number will create a brand new object for the new value; that distinction is critical.
  • Your 'more about the language' page mentions 'Batch mode' - no-one I know calls it that. Please use the right terminology.
  • Constructs page : Most beginners wont understand what 'constructs' mean, and if they do, they aren't beginners; I would suggest a page titled making decisions, and another page entitled loops.
  • Constructs page: you mention that indentation is counted as 4 spaces - stricly this is wrong - you can use any level of indentation you want so long as your blocks are consistent. I know indents of 4 spaces are recommeded by you can use 1 space, 3, 8 or anything.
  • Constructs page: You give this example :
    for i in range(len(l)):
        print(l[i]) 

This is so horrible that it is strongly discouraged. If you need to have the index of an item of the list - do this :

for index, item in enumerate(my_list):
     print(index, ':', item )
  • Constructs page : I appreciate you attempting to show your indentation - but I am not sure using [] to illustrate where the intendentations are works - is there a different way to do this ?
  • Constructs page : No mention of else after a loop so that you can execute code only if the list doesn't execute a break.
  • Your list, sets, dicts page contains no details of how to iterate around these (i.e. a for loop), and no mention of using enumerate while iterating to get the index and the element.
  • Your file handling section is poor to be honest - you do a readline() before each loop; not only is this superfluous, but with a very large file you could well end up filling memory. You appear not to realise that an an open file is an iterator (it has been since Python2.3) or earlier, which means you can use a for loop to iterate around the file contents
  • No mention of 'with' to open file safely (i.e. ensure it is always closed). This is much prefered than using open/close and hoping nothing goes wrong.
  • Your file handling page mentions list comprehensions - should this be in the list,set,dict page - or a page on it's own ? Also - no mention of dict or set comprehensions.
  • Exception handling - no mention of using 'else' to execute code if no exception is triggered - different from 'finally'
  • Functions - No mention of mutating arguments (if a function is passed a mutable value as an argument, and the function changes that value, then the calling function will see that change).
  • Functions - no mention of not using 'mutable objects' as default arguments - it doesn't do what most beginners think it should.
  • Todo list manager : Instead of using a '|' to separate title and content and text files - why not show your students the better way to do things - each task should be a dictionary - that enables you to extend the dictionary later - maybe with due dates etc. and then use the pickle library to save and load your list of tasts. It is far better to do that than to try to use text for complex data.
  • CSV to sql - why not use the CSV reader module - you should be showing your students the power of the standard library rather than writing their own.

Please - try to fix these issues - as I say - I applaud you for trying - but if you want to teach - teach best practice.

Hey, Thank you for such a detailed comment. I don't have much time to respond to your entire issue comment, I'll just comment on the last one.

CSV to sql - why not use the CSV reader module - you should be showing your students the power of the standard library rather than writing their own.

Because I don't believe that students should use the standard library. I believe, very strongly, that students should build their own libraries at the start and then slowly acquire best practices. Why do I believe that? Because programming is an art and art is perfected with time. I don't want to teach students best practices since day one because I believe that deprives them from the learning experience. Just imagine you are in the first grade and your teacher teaches you everything, how to dress how to eat and she teaches that to every student in the entire freaking world. That becomes a bland world. We don't need everyone to write code in the same way, we don't need mindless drones. We need a choice. We need to make people understand that they ought to code using best practices.

Now coming to the second part, this book is not about getting to becoming the master of Python. This is the absolute basics, students are encouraged to read the standard library (I hope I wrote it down in the book somewhere, I am sorry if I forgot that) and to read the entire documentation end to end.

I truly believe that programming is picked up from reading the code, just like writing is. So, I don't want to turn people into 'best practice' programmers, I want them to understand that this is Python and this is the way you code in it, but this is not the final book or any final document as far as their Python journey is concerned. This is the first step and in the first step, they'll learn the language.

Now the onus of best practices is on them because I won't be spoon feeding them with everything. They have to get out in the real world and find out what is the best way to code, they have to contribute to FOSS projects.

Compare this with raising a child or writing a novel. What you are asking me to do (teach best practices from the start) is tantamount to raising the perfect kid or writing a first draft so well that you publish it directly. It doesn't work in this way in the real world, in the real world there are a lot of crappy first drafts, and endless intermediate drafts until you get a publish worthy novel.

In the real world, you can't always teach your children to be the perfect adults that they should be. They need to understand the why part of it. Why do they need to not jaywalk or litter the street? Because it is a bad thing for our nation and our world.

I understand that we must have a difference of opinion on this, I do promise to put in this note there and update the examples too, asking them to refer to the countless best practices document in the world and I'll rethink my philosophy of not teaching the 'right way' of writing python code. I understand that I must be having my gaps in understanding or negative influences of controlled environment (aka reading 1984! I really believe in giving choice)

No - the onus of best practice is for you to be their role model;

I wrote this guide for total beginners, so my idea was that people who are totally new to Python will learn the basics here and then they'd go to learn the advanced version somewhere else. That is why this guide isn't complete! (it misses out on a lot of things that I thought wouldn't be suitable for total newbies like the magic of enumerate, it might seem silly to you now, but when I learnt Python, I was scratching my head about a lot of things, that's why I kept this book as simple as I could.)

So - the book is more about learning how to code in procedural language - rather than learning Python ?

The book is about demystifying the magic of Python. I have trained a hundred people in Python by now and for the first day they are totally blank about how exactly this for loop works and wtf are lists and all and a lot of other things. We have written code in Python so we don't appreciate the struggle they go through. It is for such students that this book was written. This guide doesn't claim to be the perfect guide, it is not. It is a beginners guide and beginners have bigger problems than writing PEP8 standard code!! They don't understand anything in the language, so I didn't put in PEP8 styling and all. That comes later, when they are comfortable and I think I have put it in the guide as well that while this is a newcomers guide, you are strongly recommended to check the best practices.

But that being said, I understand the need to teach the right way, I'll change the code and use the best practices, for if we teach them to walk incorrectly how will they run!

But your students aren't children - so the comparison is invalid.

I disagree because I wrote this book to go hand in hand with the training I give, so for me, they are like my children.

Python provides the standard library for a reason. Please use it.

Yes, in production and when you write code for real applications then you are to use the stdlib but not when you are learning the language. Just imagine if you don't ever learn how to write a csv parser and you just use the csv library then what kind of programmer will you become?

When I was learning coding, all books taught me to use the stdlib, it took me many many hours to learn programming on my own by tinkering. I agree that you learn coding by tinkering, but I learnt it by reading the source code for Python itself.

I'll probably have to mention this in the book that "While you are not using the stdlib in this book, you are encouraged to not reinvent the wheel later"

I am saying this by example, one of the worst ways of teaching how to write code is telling students to use the stdlib. Yes, stdlib is well tested and is to be used after you know the internals!!

Can I suggest an alternative - rather than asking your students to cut

What I can do is, I'll ask them to write their own version of a csv parser and then use the stdlib. That way, they'll learn to use the stdlib and know how to write actual code. Best of both worlds!!

I am not even as old as the number of years of programming experience you have, but I have learnt a few languages and frameworks on my own and I faced a lot of challenges which made me write these guides (which are example based and cut out on a lot of theory).

The one thing I haven't been able to forget is the frustration I went through when I picked and gave up on almost every book I read about C/C++/Java.

I had no mentor, guide or teacher to help me, I didn't even know what StackOverflow was(back then). I did everything via books and most of them taught me how to use a CSV parser on the first chapter when I didn't even know what a CSV is or what a parser was. Not a single book taught me via easy to understand examples which could fit my newbie's head.

It is perhaps the greatest tragedy in the field of programming that the 'beginners books' are written by those who have 30+yrs experience in programming, who don't know how frustrating it is to not understand a word written by experts (and then feeling that you are as dumb as a soup for not understanding the classic, Dennis and Ritchie's The C Programming Language).

When you are a total newbie, everything is magic, when we learn those things, 'the curse of knowledge' sets in which makes us blind to the struggle we had lead while we were learning the language and it is for that reason even my youtube channel gets regular comments literally saying

Thankyou folks i have watched so many videos but your video made me clear about indentation

Great video. Had searched for such clear, basic to a higher level explanation, but didn't find that anywhere, until now. Thank you. Keep up the awesome work ! :-)

thank you so much for this tutorial .I did not realise how important indentation was in python because even if your code is correct it will not run if the indentation is not properly applied

link to one such video

This is because most newbie books are too arcane for newbies!!

Of course by now means I encourage reinventing the wheel, I don't encourage reading the stdlib, but I do encourage them to write code to do everything and not use the stdlib for the course, of course, I encourage them to use the stdlib strictly, but only after the course, not during it.

I am teaching them to drive but I keep the "Autonomous driving" feature off, let them understand how to shift gears first before sitting back and relaxing while the AI does the driving.

That being said, I agree with you with the fact that the examples in this guide are woefully inadequate, the students can indeed write something more using the stdlib, I'll perhaps add a few more chapters. But truth be told, I can barely finish this guide in seminars in 10 days, there is always so much content to teach and time is always short.

@TonyFlury
I have made significant changes to the existing draft based on your feedback. I'll be posting them soon (within a few months). Thank you for opening my eyes! I was kind of living in an echo chamber.