Black Lives Matter. Please consider donating to Campaign Zero's mission of ending police violence in America.

Newbie finds naming snobbish

Some observations from a new user, for what they’re worth.

The app callback functions are, how do I put it, snobbish? Specifically, the variable/parameter “input_value” Here’s what I have to start with:

    Output(component_id='my-div', component_property='children'),
    [Input(component_id='my-id', component_property='value')]
def update_output_div(input_value):
    return 'You\'ve entered "{}"'.format(input_value)

Don’t we always expect a variable to be declared somewhere so we always understand context? I mean this broadly, not just in programming. If I wanted you to bring me something from the kitchen table I wouldn’t make up a word and say, bring me the “tokoticoat”. I’d point to the item and say, bring me the “honey”. Or, I might just say “bring me what’s on the table” so you know the item is a dummy variable of the table.

In the above sample code, “input_value” seems to be a real name, like “honey”. But I don’t see it declared anywhere. I feel stupid, what does everyone else know about “input_value”?

Then I noticed that if I put in “tokoticoat” it works the same. Why, because the function under the callback takes whatever was put into the input. It’s a parameter name you call whatever you want. I’m new to this, am I wrong? Philosophically, should anything be named that we have no control over?

A better variable would just be an underscore say, so

    Output(component_id='my-div', component_property='children'),
    [Input(component_id='my-id', component_property='value')]
def update_output_div(_):
    return 'You\'ve entered "{}"'.format(_)

Or maybe “dash_callback_input”

Declarative programming can be very powerful. It can also be inscrutable. I’m finding it very frustrating and feel some of it can be avoided.

Again, just my observations before I learn this stuff and move on. If you want more Dash adoption, I believe you need to be kinder to a new person’s naming expectations. Back to having some fun!

This variable can be named anything. It is simply the parameter of the function and therefore isn’t declared anywhere else. How Dash works behind the scenes is that @app.callback decorator “registers” the input and outputs to the function and then Dash will “call” your function (update_output_div) passing in the inputs in positional order. So, update_output_div can be named anything you want and the input arguments of your function can be named anything you want. The important thing is the order of the arguments: it should match the order of the [Input(...), ] that you supply in the @app.callback decorator.

If you are interested in learning more about the @app.callback syntax, I highly recommend crunching through this explanation on decorators: This is how I originally learned about them years ago!

I am interested. And I am reading everything I can find. If you’re interested in how a new person reacts to your marvelous work then you should read what I wrote again. Not everyone will “crunch” through the explanations. I will. I’m just trying to help you gain more adoption. And to do that, I believe you need to be more critical of unnecessary confusion you’re causing by not working harder to make your variables and sample code readable. You’re just digging in and basically saying the problem is with me because I haven’t read the documentation (which I have).

I couldn’t do what you’ve done. It’s rocket science to me. Again, up to you what IQ level you want to make your cut-off at :wink: I will try to make the cut! Just wanted to let you know it won’t be easy for me. Thanks!

One last thing, question for you, what rules do you follow to call a variable which the user has no control over and which the name is arbitrary? You used “input_value” in your demo, I’ve seen others use “value” It’s not a question of if it works or not. It does. The question is how much time do you want a new user to spend trying to figure things out what’s going on? That’s my main point. And as I work on it I will try to share what I’ve learned with others. I just felt I should tell you and others about this main thing that seems to be confusing a lot of people. Variable names. Variable scope.

Oh and thanks for the feedback. Will go read now!

Okay, I’ve read it. Still trying to digest it. But my first takeaway is that decorators reduce the number of lines of code you need to write but with a SEVERE comprehension penalty. I’m very rusty with this programming stuff but I don’t see how a simple on_change event would suffice here and make the code much more readable. Again, I’m new to this. The more I look into this, the more I believe DASH is only the top 1% of programmers. I believe there’s a thing as TOO Pythonic :wink: I’ll keep trying.

Thanks for your feedback @maxrottersman

You’re welcome! This stuff is wicked cool!

I’d like to politely disagree that Dash is only for the top 1% of programmers. I haven’t done any coding since I was in college in the 80’s (pre internet!) and when I found Dash I thought it was so cool, it inspired me to learn Python. Sure, I had to learn the basics, but I had my app live within a couple of weeks. It’s an amazing product!

Thanks for your comment! Though, if you coded in the pre-internet you’re probably in that 1% :wink: I agree, it is an amazing product!!!