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 6739627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:30:41+00:00 2026-05-26T11:30:41+00:00

So, another question on what is Pythonic! The application domain in this case is

  • 0

So, another question on what is Pythonic! The application domain in this case is network algorithms (as in, nodes, edges, Dijkstra, that kind of thing…), something I have only previously coded in strongly typed languages where we can be very certain what everything is.

Meanwhile in Python, I’ve got a class Net; a single instance of this class represents a network. I have a class Edge which is instantiated for each edge in the network. Each Edge instance has, among other things, a unique id.

Sometimes I wish to remove an edge by reference to the relevant Edge instance. Other times I wish to remove an Edge using its id. To be honest, I’m starting to lose track of which variables are Edges and which are ids. I think I preferred C++ for this job 😛

So I propose two solutions:

  1. Start using systems Hungarian notation – name my variables better so I know whether they are actual Edge objects or just the id of the Edge I want. Implement strong typing – make remove_edge (which is a method on Net) explicitly reject anything that isn’t an Edge. Make a wrapper function remove_edge_id which looks up the relevant Edge from its id and then calls remove_edge; this function likewise rejects anything that isn’t an id.

  2. Use duck typing. Have remove_edge check whether the argument is an id or an Edge and just do the right thing with it.

Whadday’all reckon?

  • 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-26T11:30:41+00:00Added an answer on May 26, 2026 at 11:30 am

    The duck-typing solution is by far more Pythonic. However, rather than testing the argument to see whether it’s an ID or an edge, just treat it as if it were the more common case first, and if that doesn’t work, try it the other way.

    If you do use explicit type-checking, which is sometimes the only way, use isintance() rather than type() so it’ll work with subclasses.

    A variable can be well-named or poorly-named, which is orthogonal to whether you are using strong typing or not. If you have some variables that reference an Edge ID, and others that reference an Edge instance, distinguishing them in some way seems smart even if you’re using duck typing. I’d use something like edge and edge_id rather than Hungarian though.

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

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
Another question following on from this thread . The only remaining item that I
In another question , a user pointed out that the new keyword was dangerous
In another question it was recommend that I try resetting a remote tracking branch
Another question on SO inspired me to try this code in C#: class Program
In another question I asked about alignment this was given to me to answer
In another question I was worried about using a web service that takes a
(In Python 3.1) (Somewhat related to another question I asked , but this question
In another question I asked, raised a concern that spring framework is not type
This question is in relation to another question I have asked, but what are

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.