Author Topic: What's your favorite language feature?  (Read 3598 times)

0 Members and 1 Guest are viewing this topic.

Offline IDEngineer

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: us
Re: What's your favorite language feature?
« Reply #25 on: March 23, 2020, 02:50:45 am »
Saw this thread and had to comment, since I just had to learn Python for a small side project....

You'll never realize how much you appreciate braces surrounding (read: clearly, unmistakably delimited) code blocks in C/C++, until you work in a language like Python where (invisible) (whitespace) indent levels attempt to substitute for them.

Whomever dreamt that up should be professionally embarrassed for eternity. No other accomplishment can possibly offset the lunacy of that decision.

EDIT: If we can take visible code block delimiters for granted, then my favorite language feature is pointers. Can't think of a single other feature that is as powerful and flexible. Can pointers be misused? Sure, just like any other powerful tool in any context. It's the wrong approach to cripple a language so you can better tolerate poor software authors. Hint: Poor software authors will always find ways to leave bugs in their code.
« Last Edit: March 23, 2020, 02:59:53 am by IDEngineer »
 
The following users thanked this post: AlfBaz, BillyD, bsudbrink

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #26 on: March 23, 2020, 02:45:04 pm »
You'll never realize how much you appreciate braces surrounding (read: clearly, unmistakably delimited) code blocks in C/C++, until you work in a language like Python where (invisible) (whitespace) indent levels attempt to substitute for them.

Whomever dreamt that up should be professionally embarrassed for eternity. No other accomplishment can possibly offset the lunacy of that decision.

Ahah, I fully agree. This is wrong on so many levels, but one that's definitely worse than others is maintainability and code sharing.

More generally speaking, this is a pet peeve of mine actually: many people seem to be in the quest for minimizing the number of characters they have to type when writing code, and blame overly "verbose" languages. C is already pretty lean, but some people find it still too verbose and want to get rid of more signs like braces and parentheses.

I think this is completely dumb, and often say that if the number of characters you have to type to write a given piece of code really matters to you compared to all other design and implementation tasks, then the code you write must be either really simple or really lame.

Just my 2 cents. ::)
 
The following users thanked this post: cliffyk, BillyD, dbctronic

Online jfiresto

  • Frequent Contributor
  • **
  • Posts: 317
  • Country: de
Re: What's your favorite language feature?
« Reply #27 on: March 23, 2020, 04:17:01 pm »
Almost always when I found something annoying about Python, it was because I was slavishly following a design pattern, necessary in a prior language I had internalized, but now redundant in Python and agreeably forgotten.

I think the missing delimiters and significance of whitespace bit me once or twice the first couple days I used Python. That ended after I banished tabs and turned on Python mode: in the same old editor I have been using for the last forty years. The pretty printing I had always done, then mapped one-to-one to Python's indentation, and I promptly forgot about it.

I bet you are fighting the language in some way if its indentation is causing you grief,  If you could post some examples (perhaps starting another thread), I would be happy to try to smooth things out.
« Last Edit: March 23, 2020, 04:28:46 pm by jfiresto »
 

Offline exe

  • Supporter
  • ****
  • Posts: 1711
  • Country: nl
  • self-educated hobbyist
Re: What's your favorite language feature?
« Reply #28 on: March 23, 2020, 04:31:34 pm »
Strong static typing (I'm a python developer).
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 12164
  • Country: gb
    • Having fun doing more, with less
Re: What's your favorite language feature?
« Reply #29 on: March 23, 2020, 04:42:12 pm »
You'll never realize how much you appreciate braces surrounding (read: clearly, unmistakably delimited) code blocks in C/C++, until you work in a language like Python where (invisible) (whitespace) indent levels attempt to substitute for them.

Whomever dreamt that up should be professionally embarrassed for eternity. No other accomplishment can possibly offset the lunacy of that decision.

Ahah, I fully agree. This is wrong on so many levels, but one that's definitely worse than others is maintainability and code sharing.

More generally speaking, this is a pet peeve of mine actually: many people seem to be in the quest for minimizing the number of characters they have to type when writing code, and blame overly "verbose" languages. C is already pretty lean, but some people find it still too verbose and want to get rid of more signs like braces and parentheses.

I think this is completely dumb, and often say that if the number of characters you have to type to write a given piece of code really matters to you compared to all other design and implementation tasks, then the code you write must be either really simple or really lame.

Just my 2 cents. ::)

Precisely.

I'll add "... or you are only coding what somebody else designed".

With any decent language a modern IDE should be able to type many of the characters: in Eclipse it is ctrl-space then a few arrows to select the precise option you want. No, C/C++ cannot (by design) count as decent in this respect.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline IDEngineer

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: us
Re: What's your favorite language feature?
« Reply #30 on: March 23, 2020, 05:32:31 pm »
I think the missing delimiters and significance of whitespace bit me once or twice the first couple days I used Python. That ended after I banished tabs and turned on Python mode: in the same old editor I have been using for the last forty years.
Just to be clear, my Python code works just fine. And I use IDLE, straight out of the Python distribution, so it's not an "editor thing".

It's in reading and (especially) debugging, and especially when it's someone else's code, that Python's block delimiter mistake becomes very apparent. There's just no way that the visual absence of something is as clear and quick to recognize. This is particularly bad with nested loops. One of the things I had to write in Python recently was some matrix manipulation code, and the nested loops where a pain for everyone on the team. I lost count of the number of times one or more of us was carefully examining a line of code in the wrong loop because the visibility of the indent level was affected by your angle to the screen - if you weren't straight in front of a monitor it became very easy to misjudge which indent level you were tracking by eye. Utter insanity! And so easily avoided, as has been done in other languages for decades. This was a completely avoidable error in language design.

It also doesn't help, if you're going to rely on whitespace, that the default indent is just four spaces. I like tight indenting when block delimiters are in use, but when whitespace on the screen is all you've got, four little spaces makes things just that much harder. Particularly in a team environment and it's not YOUR screen so you're off-axis.

Finally, Python isn't even consistent in its elimination of block delimiters. It actually has an OPENING delimiter (the colon), which basically substitutes for (say) the open brace in C, C++, Java, etc. But Python's closing delimiter is - wait for it - a correct number of spaces from the left edge. Which is a number that varies depending upon where the associated colon happens to be (or, rather, where the line that contains that colon happens to start). And it's up to the user to line everything up, visually, through blank white space across potentially many lines on the screen, to avoid (best case) compile errors or (worst case) unintended code behavior.

All of which could have been easily eliminated with a closing block delimiter. And that wouldn't have even been a new concept in the world of programming languages. Unbelievable.

EDIT: A good related question to this topic is "What problem were they trying to solve by eliminating the closing block delimiter?" Honestly, how many times have programmers pounded their keyboard in frustration and shouted "My life would be so much better if there was a language out there that DIDN'T require a closing block delimiter!!!" I've said, and heard, that complaint precisely zero times.
« Last Edit: March 23, 2020, 05:36:50 pm by IDEngineer »
 
The following users thanked this post: techman-001

Offline Tepe

  • Frequent Contributor
  • **
  • Posts: 571
  • Country: dk
Re: What's your favorite language feature?
« Reply #31 on: March 23, 2020, 05:33:59 pm »
Pattern matching (like in SML or Haskell)
ceterum censeo systemd-inem esse delendam
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #32 on: March 23, 2020, 06:03:20 pm »
(...)And it's up to the user to line everything up, visually, through blank white space across potentially many lines on the screen, to avoid (best case) compile errors or (worst case) unintended code behavior.

All of which could have been easily eliminated with a closing block delimiter. And that wouldn't have even been a new concept in the world of programming languages. Unbelievable.

Yep!
It just looks like a decision from some hugely stubborn person, not completely different from some religious belief. The amount of potential problems it introduces just to save one delimiter is, as you said, unbelievable! But as I said in an earlier thread, I don't think the author of Python ever expected it to become so popular either.

This meaningful blank space disaster always makes me think of the Whitespace language: https://en.wikipedia.org/wiki/Whitespace_%28programming_language%29
 ;D (note that Python is actually cited in this article, which is extra funny.)
« Last Edit: March 23, 2020, 06:59:43 pm by SiliconWizard »
 

Offline IDEngineer

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: us
Re: What's your favorite language feature?
« Reply #33 on: March 23, 2020, 08:27:44 pm »
This meaningful blank space disaster always makes me think of the Whitespace language: https://en.wikipedia.org/wiki/Whitespace_%28programming_language%29
 ;D (note that Python is actually cited in this article, which is extra funny.)

Yep! I saw its reference to Python and literally laughed out loud!

Quote
It just looks like a decision from some hugely stubborn person, not completely different from some religious belief. The amount of potential problems it introduces just to save one delimiter is, as you said, unbelievable! But as I said in an earlier thread, I don't think the author of Python ever expected it to become so popular either.
And ironically, one of the things people say they like about Python is the availability of off-the-shelf libraries. As if those are a whole new Python invention.

I don' t know Python's history but it feels very much like a weekend joke similar to the Whitespace language that got taken WAY too seriously. What unique value does it deliver? Let's see... interpreted language? Yep, those existed before. Importable libraries? Check. Some degree of object orientedness? Bingo. Copies C just enough to shorten the learning curve? Yep, been done. Limits flexibility in an attempt to "protect bad programmers from themselves"? Everywhere these days.
 
The following users thanked this post: bsudbrink

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #34 on: March 23, 2020, 09:24:26 pm »
 

Offline IDEngineer

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: us
Re: What's your favorite language feature?
« Reply #35 on: March 23, 2020, 10:29:22 pm »
The history is summed up here: https://en.wikipedia.org/wiki/Python_(programming_language)
Whoa. From TFA:

"Python 3.0, released in 2008, was a major revision of the language that is not completely backward-compatible, and much Python 2 code does not run unmodified on Python 3."

Just throw most existing code under the bus?!? Yessir, THAT's a "professionally managed platform" that I'd want to use as the basis for commercial projects. NOT.

Thanks for citing that article. Every time I think I've encountered the worst aspect of Python, something else surfaces to take the award.

EDIT: "Python 2.7's end-of-life date was initially set at 2015 then postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to Python 3." Darned considerate of 'em, eh?
« Last Edit: March 23, 2020, 10:32:18 pm by IDEngineer »
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 1786
  • Country: fi
    • My home page and email address
Re: What's your favorite language feature?
« Reply #36 on: March 23, 2020, 10:59:28 pm »
I just had to learn Python for a small side project....
There is a difference in using a tool as a hammer, and using it effectively, though.

I've seen tons of code written in a language as if it was originally written in another programming language, then filtered through the equivalent of Google Translate.  The results are.. well, best deleted.

To me, the complaints about Python using indentation for code blocks is similar to complaining about Perl's variable type prefixes ("sigils": $, @, %, and &).

I do not believe one has truly understood a programming language until they see the beauty in at least some of its expressions.  Even Brainfuck has such beauty; you just need to swivel your brain and viewpoint enough to see it.  It is only then that things become truly interesting.
 

Offline ivaylo

  • Frequent Contributor
  • **
  • Posts: 636
  • Country: us
Re: What's your favorite language feature?
« Reply #37 on: March 24, 2020, 05:12:40 am »
Yeah, I liked this thread until it turned into a Python bashing party.
 

Online jfiresto

  • Frequent Contributor
  • **
  • Posts: 317
  • Country: de
Re: What's your favorite language feature?
« Reply #38 on: March 24, 2020, 02:35:41 pm »
The bashing has, however, made me better appreciate languages that follow the off-side rule.

So, another favorite: syntax that makes a language look like executable pseudo-code.
« Last Edit: March 24, 2020, 02:42:22 pm by jfiresto »
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 7416
  • Country: us
Re: What's your favorite language feature?
« Reply #39 on: March 25, 2020, 03:47:09 pm »
I kind of like the nested block structure of a language like Pascal where functions or procedures can be local to surrounding functions or procedures.
I also like 'sets' as provided by Pascal.
Pascal code is simply elegant.  Everything else is less elegant.

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #40 on: March 25, 2020, 04:10:51 pm »
Pascal code is simply elegant.  Everything else is less elegant.

Many Pascal derivatives are also just as elegant, like Modula, Oberon... (but those are even more of niche languages than Pascal, so...)
Of course we can mention ADA, which also is a niche language (although still used and still evolving) Many find it too intimatiding or something, but it can be pretty elegant too.

 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2024
  • Country: nl
Re: What's your favorite language feature?
« Reply #41 on: April 01, 2020, 03:12:24 pm »
I kind of like the nested block structure of a language like Pascal where functions or procedures can be local to surrounding functions or procedures.
I also like 'sets' as provided by Pascal.
Pascal code is simply elegant.  Everything else is less elegant.
I kind of like the nested block structure of a language like Python where functions can be local to surrounding functions.
I also like 'sets' as provided by Python, including the various operators acting upon them such as union, intersection, set difference, etc.
Quake II Chaos Deathmatch is simply elegant.  Everything else is less elegant.  ;) ;) ;)   <-- (*)

On a more serious note ... another reason for using sets (in python) as opposed to say lists, is that membership tests are pretty fast (read: hash table).
And along the lines of nested functions, parameterized functions are also pretty handy.

Code: [Select]
def parameterized_multiplier(param):
    def multiply_this(x):
        return param * x
    return multiply_this

mul7 = parameterized_multiplier(7)
print(f"Answer to the Ultimate Question of Life, the Universe, and Everything: {mul7(6)}")


(*) I would have used bouncy proximity mine emoticons, but for some strange reason this forum does not have them. :-//

Oh oh oh! I just thought of a solution for this horrible lack of emoticon problem! Just migrate the forum to Discourse. That should surely solve any and all problems. :)  Not only that, but it should also
"improve engagement with younger audiences (???)". Not entirely sure about the requirements for that particular phrase, but as a first order approximation I'll go with  ;) ;) ;) ;) ;).
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #42 on: April 01, 2020, 04:01:47 pm »
I kind of like the nested block structure of a language like Python where functions can be local to surrounding functions.

I personally think nested functions/procedures are a bad idea both for code readability and code structure. Wirth himself (the author of Pascal) got rid of them in later derivatives of Pascal, like Oberon.
I admit I liked them back when I used Pascal, but I changed my mind over time, just like Wirth did.

Modules are a much better way of structuring code and hiding/making things local than nested functions IMO. Unfortunately, modules are still supported only in a very small number of languages, but you can more or less emulate them with almost any language. In C, just declare functions you would otherwise like to nest, static and partition your code in as many source files as required to make code clearer and isolate "helper" functions.

One obvious downside of nesting functions is that it makes functions including other functions way too long overall, which hinders readablity. They initially look like a good idea, but you end up realizing they're not.

 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2024
  • Country: nl
Re: What's your favorite language feature?
« Reply #43 on: April 01, 2020, 05:06:37 pm »
I personally think nested functions/procedures are a bad idea both for code readability and code structure.
Heh, I tend to use nested functions precisely where (I think) it will improve code readability. Typically it will be where you have a function that contains doing roughly the same thing a few times. Okay, DRY, so make a separate function out of it. But wait, this new separate function does need an aweful lot of information that is only available within the scope of our existing function (the one we are refactoring). No problem, lets just all pass them as arguments. Sure, you can do that. But it does mean that you now have lines like this:

Code: [Select]
result = nice_non_nested_function(central_bit_of_information_for_this_particular_operation,
                                  always_the_same_for_entire_scope_of_original_large_function1,
                                  always_the_same_for_entire_scope_of_original_large_function2,
                                  always_the_same_for_entire_scope_of_original_large_function3,
                                  always_the_same_for_entire_scope_of_original_large_function4,
                                  always_the_same_for_entire_scope_of_original_large_function5)

I would rather have:
Code: [Select]
result = evil_nested_function(central_bit_of_information_for_this_particular_operation)

Because with the latter it is fairly obvious what the central bit of information is for this particular operation.

As for modules ... yes, no, maybe. As with everything, it depends. There's a fair chunk of functionality vs code complexity where separating it and stuffing it in a module is overkill IMO. As a general rule, the main thing I use to determine nested vs separate is readibility. If all went well, after refactoring the resulting function containing the nested function should be 1) less lines total, 2) less visually cluttered, 3) have clearer intent.
 

Online guenthert

  • Frequent Contributor
  • **
  • Posts: 394
  • Country: us
Re: What's your favorite language feature?
« Reply #44 on: April 21, 2020, 11:37:48 pm »
The ternary operator.
  I prefer a language which doesn't make the distinction between statement and expression and consequently doesn't need crutches like the ternary operator.
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 2530
  • Country: 00
Re: What's your favorite language feature?
« Reply #45 on: April 22, 2020, 12:01:59 am »
I kind of like the nested block structure of a language like Python where functions can be local to surrounding functions.

I personally think nested functions/procedures are a bad idea both for code readability and code structure. Wirth himself (the author of Pascal) got rid of them in later derivatives of Pascal, like Oberon.
I admit I liked them back when I used Pascal, but I changed my mind over time, just like Wirth did.

Modules are a much better way of structuring code and hiding/making things local than nested functions IMO. Unfortunately, modules are still supported only in a very small number of languages, but you can more or less emulate them with almost any language. In C, just declare functions you would otherwise like to nest, static and partition your code in as many source files as required to make code clearer and isolate "helper" functions.

One obvious downside of nesting functions is that it makes functions including other functions way too long overall, which hinders readablity. They initially look like a good idea, but you end up realizing they're not.

IMHO nested functions look good if the functions are relatively short (a handful of lines), there are not many of them, and they clearly belong only to the scope of the parent.   With long functions, the overview disappears and it feels better to encapsulate it some other way.
 

Offline Tepe

  • Frequent Contributor
  • **
  • Posts: 571
  • Country: dk
Re: What's your favorite language feature?
« Reply #46 on: April 22, 2020, 02:08:17 pm »
I personally think nested functions/procedures are a bad idea both for code readability and code structure. Wirth himself (the author of Pascal) got rid of them in later derivatives of Pascal, like Oberon.
From the Oberon report: "Since  procedures may be declared as local objects too, procedure declarations may be nested."
ceterum censeo systemd-inem esse delendam
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5454
  • Country: fr
Re: What's your favorite language feature?
« Reply #47 on: April 22, 2020, 03:33:53 pm »
I personally think nested functions/procedures are a bad idea both for code readability and code structure. Wirth himself (the author of Pascal) got rid of them in later derivatives of Pascal, like Oberon.
From the Oberon report: "Since  procedures may be declared as local objects too, procedure declarations may be nested."

Had to re-read it (latest Oberon-07) and that's right. I can't remember exactly now when Wirth talked about that, but I'm pretty sure I remember him saying they were not a good idea.
But I've studied Oberon a while ago and I don't think I've ever run into nested procedures in any code example I've seen, including the Oberon OS itself.

Anyway, as I said above, I can't see much benefit for them  - they just clutter up functions/procedures, would possibly mess up classic code metrics, and just make your functions too long, which hinders readability.

Helper functions can always be declared non-nested in most current languages without having to resort to nesting them. All you need is modularize your code in the best way you can with the features of your language. Even in C, just declare your helper functions static. I do consider that any function that is not "exported" (in C meaning: static, not visible to other compilation units) is an "helper" function anyway. It has no other purpose. The only thing nesting would give you is make said function invisible to the rest of the code in the same compilation unit (from its declaration down to the end of the source file), which is really not that much of an advantage in real life IME.

Another point "against" nesting is that it may look like it makes sense to nest some helper function when you write it, but later on said helper function may actually be useful for something else. That's very likely to happen if you write your code as "reusable" as possible, and is actually not "risky" (which nesting would mitigate) if your functions are well documented and well written. So in a way, function nesting would be likely to somehow favor non-reusable code IMHO.

Yet another point is the following: the possibility (like with local variables) to "hide" declarations with a similar name, which could lead to confusion, or bugs. I think this is more likely to happen, as if using nested functions, you're likely to give them a shortened name (identifier), with more possibilities of name "clashing" in a larger project.

Of course this is very much a coding style question, and there will be as many opinions as there are people, or almost. This was just mine.
« Last Edit: April 22, 2020, 03:38:13 pm by SiliconWizard »
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 2530
  • Country: 00
Re: What's your favorite language feature?
« Reply #48 on: April 23, 2020, 01:48:09 am »

You could use a naming scheme for local variables, e.g. lv_Count,  lv_Index,  etc. etc. to avoid confusion.   Nested/local functions could also have a naming scheme.  As long as you're consistent, you'll never be confused with variable scope again. 



 

Offline boffin

  • Supporter
  • ****
  • Posts: 963
  • Country: ca
Re: What's your favorite language feature?
« Reply #49 on: June 18, 2020, 05:48:54 pm »
"Python 3.0, released in 2008, was a major revision of the language that is not completely backward-compatible, and much Python 2 code does not run unmodified on Python 3."

Just throw most existing code under the bus?!? Yessir, THAT's a "professionally managed platform" that I'd want to use as the basis for commercial projects. NOT.

Pretty much like Java which every 18 months comes out with a new revision that breaks all the existing code. This forces enterprise developers to include their own copy of Java in their product so it doesn't happen, but that has security vunl etc etc.   

DEATH TO JAVA
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf