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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:17:09+00:00 2026-05-11T01:17:09+00:00

Many years ago I remember a fellow programmer counselling this: new Some::Class; # bad!

  • 0

Many years ago I remember a fellow programmer counselling this:

new Some::Class;    # bad! (but why?)  Some::Class->new(); # good! 

Sadly now I cannot remember the/his reason why. 🙁 Both forms will work correctly even if the constructor does not actually exist in the Some::Class module but instead is inherited from a parent somewhere.

Neither of these forms are the same as Some::Class::new(), which will not pass the name of the class as the first parameter to the constructor — so this form is always incorrect.

Even if the two forms are equivalent, I find Some::Class->new() to be much more clear, as it follows the standard convention for calling a method on a module, and in perl, the ‘new’ method is not special – a constructor could be called anything, and new() could do anything (although of course we generally expect it to be a constructor).

  • 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. 2026-05-11T01:17:10+00:00Added an answer on May 11, 2026 at 1:17 am

    Using new Some::Class is called ‘indirect’ method invocation, and it’s bad because it introduces some ambiguity into the syntax.

    One reason it can fail is if you have an array or hash of objects. You might expect

    dosomethingwith $hashref->{obj} 

    to be equal to

    $hashref->{obj}->dosomethingwith(); 

    but it actually parses as:

    $hashref->dosomethingwith->{obj} 

    which probably isn’t what you wanted.

    Another problem is if there happens to be a function in your package with the same name as a method you’re trying to call. For example, what if some module that you use‘d exported a function called dosomethingwith? In that case, dosomethingwith $object is ambiguous, and can result in puzzling bugs.

    Using the -> syntax exclusively eliminates these problems, because the method and what you want the method to operate upon are always clear to the compiler.

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

Sidebar

Related Questions

I remember when I switched from Classic ASP to PHP many years ago, and
I have many years of experience in Java including Swing, Servlet and JDBC, but
I used a script many years ago that was basically and administrative backend where
Since many years a GUI-standard are the menu-bars of applications with menus popping up,
I use Delphi for many years, and although I have now moved on to
Our company has for many years had multiple domain names to protect our product
As a developer who spent many years working within Visual C++ 6, I'm used
I've been a PHP developer for many years now, with many tools under my
I've been using make and makefiles for many many years, and although the concept
I've used recursion quite a lot during my many years of programming to solve

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.