python - tail stuck under the rocks?
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
It sorta makes sense, and in theory at least should encourage correct indentation. But ... that won't save it. Survey Results - If you know C, C++, C#, Objective C or Java do you also know Python?[^] Just the "no need to declare variables" sends a shiver down my spine. That's actually worse than VB could manage - and that takes some doing!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
Supporting and encouraging good (consistent) formatting is a good thing, but requiring it isn't. (In my opinion) one of the strengths of C-like languages is that whitespace is pretty much unimportant. With C and C# -- unless you have directives -- each sequence of whitespace can be reduced to a single SPACE without affecting the meaning of the code. When I write C, I try to put all the directives in their own files, away from the actual C code.
-
The first version will not work as it has a syntax error. It should be:
if x is a: # note the trailing colon
-
It sorta makes sense, and in theory at least should encourage correct indentation. But ... that won't save it. Survey Results - If you know C, C++, C#, Objective C or Java do you also know Python?[^] Just the "no need to declare variables" sends a shiver down my spine. That's actually worse than VB could manage - and that takes some doing!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
OriginalGriff wrote:
"no need to declare variables" sends a shiver down my spine.
Er, isn't that exactly why the "var" keyword was invented? A few years from now no one will be using proper typed variables any more.
Oh, no, no, no, no! Python's version is worse: you don't need to declare the variable using "var", or "Dim", or anything - just pick a name and assign a value. So if you misspell it ... that's a new variable. Just like FORTRAN was back in the day (1977). And that caused a probe to miss the planet Venus completely, so what it does in a banking app, or a Boeing 737 Max is not something you want to think about too hard, really. Strongly typed variables should be mandatory in all languages used in the 21st century!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Oh, no, no, no, no! Python's version is worse: you don't need to declare the variable using "var", or "Dim", or anything - just pick a name and assign a value. So if you misspell it ... that's a new variable. Just like FORTRAN was back in the day (1977). And that caused a probe to miss the planet Venus completely, so what it does in a banking app, or a Boeing 737 Max is not something you want to think about too hard, really. Strongly typed variables should be mandatory in all languages used in the 21st century!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
OriginalGriff wrote:
Python's version is worse
I agree, but you can still do quite a bit of damage with
var
.OriginalGriff wrote:
Strongly typed variables should be mandatory in all languages used in the 21st century!
That is definitely true; but will teachers explain that properly to their students?
-
OriginalGriff wrote:
"no need to declare variables" sends a shiver down my spine.
Er, isn't that exactly why the "var" keyword was invented? A few years from now no one will be using proper typed variables any more.
But a `var` (as in C#, say) isn't at all the same thing as an untyped (or rather, dynamically-typed) variable (as in Python). When you write `var x = 5;`, `x` is still an `int` just the same as if you'd written `int x = 5;`, you're just helping yourself save some keystrokes and letting the compiler infer the type (ok, you're not saving any keystrokes in that example, but not every type name is as succinct as `int` ;P ). You can't then turn around and write `x = "snuggles";` or the compiler will throw a fit, unlike Python where it would be perfectly legal. More and more people might be using `var`, but let's not confuse that with "no one will be using proper typed variables any more!"
-
Oh, no, no, no, no! Python's version is worse: you don't need to declare the variable using "var", or "Dim", or anything - just pick a name and assign a value. So if you misspell it ... that's a new variable. Just like FORTRAN was back in the day (1977). And that caused a probe to miss the planet Venus completely, so what it does in a banking app, or a Boeing 737 Max is not something you want to think about too hard, really. Strongly typed variables should be mandatory in all languages used in the 21st century!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
OriginalGriff wrote:
just pick a name and assign a value. So if you misspell it ... that's a new variable
but how do you misspell "i"
Message Signature (Click to edit ->)
'j'? 'u', 'o', 'k'? All easy to do, especially on a "soft keyboard". :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
'j'? 'u', 'o', 'k'? All easy to do, especially on a "soft keyboard". :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
Use Cryllic. Word doesn't match the second as 'sit': sit sіt
-
Use Cryllic. Word doesn't match the second as 'sit': sit sіt
There is also the "Extra quote character": ''' which looks just like the ones around it, but will not compile in other peoples code - not that you would replace any, I'm sure ... :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
OriginalGriff wrote:
Python's version is worse
I agree, but you can still do quite a bit of damage with
var
.OriginalGriff wrote:
Strongly typed variables should be mandatory in all languages used in the 21st century!
That is definitely true; but will teachers explain that properly to their students?
Richard MacCutchan wrote:
I agree, but you can still do quite a bit of damage with
var
.In what language? JavaScript? Certainly, but JavaScript doesn't really get much better than that... In C# it's still a typed variable, so it's exactly the same thing as explicitly using the type name except instead of the type name you use var. So no damage there, except to readability.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
But a `var` (as in C#, say) isn't at all the same thing as an untyped (or rather, dynamically-typed) variable (as in Python). When you write `var x = 5;`, `x` is still an `int` just the same as if you'd written `int x = 5;`, you're just helping yourself save some keystrokes and letting the compiler infer the type (ok, you're not saving any keystrokes in that example, but not every type name is as succinct as `int` ;P ). You can't then turn around and write `x = "snuggles";` or the compiler will throw a fit, unlike Python where it would be perfectly legal. More and more people might be using `var`, but let's not confuse that with "no one will be using proper typed variables any more!"
Dictionary<string, IEnumerable<IEnumerable<SomeValue>>> valuesPerLineFromACsvFileByKey = new Dictionary<string, IEnumerable<IEnumerable<SomeValue>>>();
or:
var valuesPerLineFromACsvFileByKey = new Dictionary<string, IEnumerable<IEnumerable<SomeValue>>>();
:D
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
I know Haskell has it too. I know, because I had a school assignment that I've been looking at for two hours because I mixed up a few spaces with a tab... X|
if x is a:
do //...Isn't the same as:
if x is a:
do //...:rolleyes: It does produce some really clean and concise code though!
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
There is also the "Extra quote character": ''' which looks just like the ones around it, but will not compile in other peoples code - not that you would replace any, I'm sure ... :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
OriginalGriff wrote:
- not that you would replace any, I'm sure
If I wasn't using a strongly-typed language, and had an asshole for a coworker that needed a lesson, I certainly would! Send him a copy in which a variable has unicode changes but looks the same: "It works for me, I can't understand why you are having problems!" :rolleyes: :rolleyes: :rolleyes:
-
Okay, that was an analogy. I was trying a little piece of Python code. Got a bit surprised with the "positional"-indentation requirements in code. Just like how it used to be in older programming languages like Cobol. (I'm not sure if any other recent programming languages enforce these) For example,
If x is a:
do //indented & worksis different from
if x is a:
do //Non-indented & throws errorIt's funny, and doesn't this sound rudimentary and a bit annoying? :)
I started looking at Python in my home hobby time around 6 months ago and while it is a bit strange at first, I now find the indentation makes the code easier to read without brackets. I know IDEs allow you to indent bracketed languages but I find that Python easier to read. If you find the indentation strange, wait until you get on to the coding standards where lines should not exceed 79 characters in length.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Oh, no, no, no, no! Python's version is worse: you don't need to declare the variable using "var", or "Dim", or anything - just pick a name and assign a value. So if you misspell it ... that's a new variable. Just like FORTRAN was back in the day (1977). And that caused a probe to miss the planet Venus completely, so what it does in a banking app, or a Boeing 737 Max is not something you want to think about too hard, really. Strongly typed variables should be mandatory in all languages used in the 21st century!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
Which is why I see Python as a poor choice for teaching beginners to 'code'. Take this class definition containing a function:
class StringFormat(object):
@staticmethod def FloatToStringFormat(num: float, decimalPlaces: int) -> str: return "{:.{}f}".format(num, decimalPlaces)
Calling it like this:
resultAsString = StringFormat.FloatToStringFormat(20.123, "2")
I would expect to get an error as I am passing in a string rather than an integer for
decimalPlaces
. But no, Python happily setsresultAsString
to "20.12"“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Which is why I see Python as a poor choice for teaching beginners to 'code'. Take this class definition containing a function:
class StringFormat(object):
@staticmethod def FloatToStringFormat(num: float, decimalPlaces: int) -> str: return "{:.{}f}".format(num, decimalPlaces)
Calling it like this:
resultAsString = StringFormat.FloatToStringFormat(20.123, "2")
I would expect to get an error as I am passing in a string rather than an integer for
decimalPlaces
. But no, Python happily setsresultAsString
to "20.12"“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
It's interesting to see in this discussion that one of python's more attractive features is seen as a disadvantage 8) Once again, the debate here about whether the language is 'good' or not seems to have nothing to do with whether it actually is good or otherwise, but simply amounts to 'does it fit my idea of how a language should work'. If I've learnt anything from over 40 years of software development, it is that (with a few domain specific exceptions) the skill of writing good software - don't mistake me here, I'm not saying that I write good software! - has almost nothing to do with the language you write it in, and everything to do with domain knowledge and the skill of the programmer(s). Every language has rules; every language has flaws. Being aware of both and using/avoiding them so you produce good code is what it's all about. The behaviour cited above as being 'problematic' is exactly why I use Python for certain types of project. 8)