Python Forum
Funny things Java Devs do but Python Devs Don't
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Funny things Java Devs do but Python Devs Don't
#2
Generators make a lot of things very easy in python that would be much harder in a lot of other languages.  Consider a simple counter:
def counter(start_value=0, increment_by):
    value = start_value
    while True:
        yield value
        value += increment_by
In another language, such as c# or java, the easiest way to do that would probably be creating a whole class for it, to maintain state, and have a next_value method.  That said, I think those languages have been adding yield features, so it may not be as true as it once was.  Newer versions of javascript, for example, would look very similar to the python above (except with braces, obviously).  But then you run the issue of your code sometimes not working, as yield was added in Firefox in 2013, but has never worked in IE (reference: http://caniuse.com/#feat=es6-generators).
Reply


Messages In This Thread
RE: Funny things Java Devs do but Python Devs Don't - by nilamo - Nov-02-2017, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Setup of VSCode to run with Python: some things are messed up apollo 0 1,483 Jan-05-2022, 12:22 PM
Last Post: apollo
  a funny code nzcan 0 2,228 Oct-31-2018, 08:51 PM
Last Post: nzcan
  things i am working on Skaperen 0 1,944 Jul-24-2018, 07:46 PM
Last Post: Skaperen
  what to order to get started with Odroid HC 2 NAS things apollo 1 2,474 Jul-02-2018, 07:57 PM
Last Post: Larz60+
  Funny English Kebap 41 25,493 Feb-10-2018, 02:06 AM
Last Post: Skaperen
  a funny coding challege Skaperen 2 3,264 Dec-07-2017, 02:26 AM
Last Post: Skaperen
  Python almost as verbose as Java Ofnuts 5 5,408 Dec-05-2016, 09:53 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020