Giter Club home page Giter Club logo

Comments (6)

PCurd avatar PCurd commented on June 11, 2024

I certainly think the method name should match the Api command. Whether it's best to keep each section as TrackApi. etc is a more difficult question.

Either way perhaps there should be an interface or abstract class for each type - I.e. an ITrackApiObject etc - which would allow conditional behaviour to be implemented if necessary.

from lastfm.

rikkit avatar rikkit commented on June 11, 2024

Whether it's best to keep each section as TrackApi. etc is a more difficult question.

Yeah I agree, I think all the commands should move to one namespace, separate from the facade objects.

Either way perhaps there should be an interface or abstract class for each type - I.e. an ITrackApiObject etc - which would allow conditional behaviour to be implemented if necessary.

How do you mean?

from lastfm.

PCurd avatar PCurd commented on June 11, 2024

Either way perhaps there should be an interface or abstract class for each type - I.e. an >>ITrackApiObject etc - which would allow conditional behaviour to be implemented if necessary.

How do you mean?

If each command inherits from the same interface and same namespace you can't easily tell which command is a Track command and which is an Album command, for example. If they inherit from a base class or interface such as ITrack... and IAlbum... you could tell what time you had by code like:

if (currentObject is ITrack...)
{
//
}

Now, you might not want to be able to do this of course!

from lastfm.

rikkit avatar rikkit commented on June 11, 2024

Now, you might not want to be able to do this of course!

IMO anything which checks the type is bad code! It's necessary sometimes but usually only as a last resort... it's a sign you need to rearchitect to make things more abstract with interfaces, generics.

What use case do you see for this? The command types aren't exposed in the public API surface so this would only affect internal usage, and I can't think of anywhere atm that relies on the type of the command used that didn't create the command itself.

If this is really needed I'd prefer extension methods that checked the API method name:

public static bool IsTrackCommand(this LastCommand command)
{
    return command.Method.StartsWith("track");
}

from lastfm.

PCurd avatar PCurd commented on June 11, 2024
public static bool IsTrackCommand(this LastCommand command)
{
    return command.Method.StartsWith("track");
}

I would always try to avoid anything with magic strings like this and would use the interface idea instead.. I guess it's a personal choice really!

My version would look like:

public static bool IsTrackCommand(this LastCommand command)
{
    return (command is ITrackCommand);
}

But I can't think of any compelling examples where this is useful. Perhaps something like making fields optional in the parser, but there's likely a better way to do this anyway.

from lastfm.

rikkit avatar rikkit commented on June 11, 2024

Yeah that example was a magic string. But magic strings are bad because they make things brittle, and imo the interface thing would be just as brittle. At least that use of the magic string cuts directly to what we want to know - whether the command is a track command (all track commands will have methods that start with "track") - instead of adding another opportunity to mis-code something (forgetting to implement the interface on track commands).

Anyway this is moot because we don't need to do this 😄

I should get to finishing reviewing your PR tonight 👍

from lastfm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.