Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1078293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:42:05+00:00 2026-05-16T21:42:05+00:00

What are the top gotchas for someone moving from a static lang (java/c#) to

  • 0

What are the top gotchas for someone moving from a static lang (java/c#) to dynamic language like python?

It seems cool how things can be done, but renaming a method, or adding/removing parameters seems so risky!

Is the only solution to write tests for each method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:42:06+00:00Added an answer on May 16, 2026 at 9:42 pm

    I would say that the number one gotcha is trying to write statically typed code in a dynamic language.

    Dont hesitate to use an identifier to point to a string and then a list in self-contained sections of code

    keys = 'foo bar foobar' # Imagine this coming in as an argument
    keys = keys.split() # Now the semantically chose name for the argument can be 
                        # reused As the semantically chosen name for a local variable
    

    don’t hesitate to treat functions like regular values: they are. Take the following parser. Suppose that we want to treat all header tags alike and ul tags like ol tags.

    class Parser(HTMLParser):
        def __init__(self, html):
            self.feed(html)
    
        def handle_starttag(self, tag, attrs):
            parse_method = 'parse_' + tag    
            if hasattr(self, parse_method):  
                getattr(self, parse_method)(attrs)
    
    
        def parse_list(self, attrs):
            # generic code
    
        def parse_header(self, attrs):
           # more generic code
    
        parse_h1 = parse_h2 = parse_h3 = parse_h4 = parse_h5 = parse_h6 = parse_header
        parse_ol = parse_ul = parse_list
    

    This could be done by using less generic code in the handle_starttag method in a language like java by keeping track of which tags map to the same method but then if you decide that you want to handle div tags, you have to add that into the dispatching logic. Here you just add the method parse_div and you are good to go.

    Don’t typecheck! Duck-type!

    def funtion(arg):
        if hasattr(arg, 'attr1') and hasattr(arg, 'attr2'):
             foo(arg):
        else:
             raise TypeError("arg must have 'attr1' and 'attr2'")
    

    as opposed to isinstance(arg, Foo). This lets you pass in any object with attr1 and attr2. This allows you to for instance pass in a tracing class wrapped around an object for debugging purposes. You would have to modify the class to do that in Java AFAIK.

    As pointed out by THC4k, another (more pythonic) way to do this is the EAPF idiom.
    I don’t like this because I like to catch errors as early as possible. It is more efficient if you expect for the code to rarely fail though. Don’t tell anybody I don’t like it though our they’ll stop thinking that I know how to write python. Here’s an example courtesy of THC4k.

    try: 
        foo(arg): 
    except (AttributeError, TypeError): 
        raise InvalidArgumentError(foo, arg)
    

    It’s a tossup as to if we should be catching the AttributeError and TypeError or just let them propagate to somewhere that knows how to handle them but this is just an example so we’ll let it fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The top of my web.xml file looks like this: <?xml version=1.0 encoding=UTF-8?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee
SELECT TOP (100) PERCENT dbo.EmployeeInfo.id, MIN(dbo.EmployeeInfo.EmpNo) AS EmpNo, SUM(dbo.LeaveApplications.DaysAuthorised) AS DaysTaken FROM dbo.EmployeeInfo LEFT
select top(10) from customer order by customer_id desc
declare @top int set @top = 5 select top @top * from tablename Is
How to top margin from first <p> paragraph after <h2> ? and if any
I am styling my top level <li> to look like tabs. and on rollover
I read a lot of good things about jqGrid on SO and would like
top.location.href doesn't work in IE8 from my facebook application when i redirect people to
SELECT top 5 day_description, count(numberofdays) as number FROM mytable where department = 'departmentname' group
select top 1 col1 from table1 order by CreatedOn desc This query takes 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.