Results 1 to 6 of 6

Thread: Is it bad coding style?

  1. #1
    Join Date
    Nov 2010
    Location
    Down the rabbit hole
    Beans
    435
    Distro
    Ubuntu Development Release

    Is it bad coding style?

    Hi,
    I'm browsing thru some code and it contains a pile of "tmp" named vars of different types.
    Have a look, is it a good coding style? Any good reason to use that many "tmp" (non mnemonic) names?
    Just wondering.

    PHP Code:
    static gboolean main_window_change_background_timeout_cb (MainWindowself) {
        
    gboolean result FALSE;
        
    gcharnew_background_file NULL;
        
    gboolean _tmp0_ FALSE;
        
    MenuBar_tmp1_;
        
    gboolean _tmp2_;
        
    gboolean _tmp3_;
        
    gboolean _tmp5_;
        
    Background_tmp11_;
        const 
    gchar_tmp12_;
        
    g_return_val_if_fail (self != NULLFALSE);
        
    _tmp1_ self->priv->menubar;
        
    _tmp2_ menu_bar_get_high_contrast (_tmp1_);
        
    _tmp3_ _tmp2_;
        if (
    _tmp3_) {
            
    _tmp0_ TRUE;
        } else {
            
    gboolean _tmp4_ FALSE;
            
    _tmp4_ ug_settings_get_boolean (UG_SETTINGS_KEY_DRAW_USER_BACKGROUNDS);
            
    _tmp0_ = !_tmp4_;
        }
        
    _tmp5_ _tmp0_;
        if (
    _tmp5_) {
            
    _g_free0 (new_background_file);
            
    new_background_file NULL;
        } else {
            
    UserList_tmp6_;
            
    UserEntry_tmp7_;
            
    UserEntry_tmp8_;
            const 
    gchar_tmp9_;
            
    gchar_tmp10_;
            
    _tmp6_ self->user_list;
            
    _tmp7_ user_list_get_selected_entry (_tmp6_);
            
    _tmp8_ _tmp7_;
            
    _tmp9_ _tmp8_->background;
            
    _tmp10_ g_strdup (_tmp9_);
            
    _g_free0 (new_background_file);
            
    new_background_file _tmp10_;
        }
        
    _tmp11_ self->priv->background;
        
    _tmp12_ new_background_file;
        
    background_set_current_background (_tmp11__tmp12_);
        
    self->priv->change_background_timeout = (guint0;
        
    result FALSE;
        
    _g_free0 (new_background_file);
        return 
    result;

    Your ads here, just 9.99$/week !!

  2. #2
    Join Date
    Sep 2009
    Beans
    217

    Re: Is it bad coding style?

    The usage of "tmp" is most certainly a bad idea. Aside from making it hard to tell what's going on, it also makes it really hard to tell if you have duplicates or unnecessary variables. At the very least, tmp2, tmp4, tmp8, tmp10, and tmp12 aren't actually being used for anything.

    Also you seem to be freeing (I assume _g_free0 is a free wrapper) new_background_file even though it starts as NULL and if tmp5 you proceed to set it back to NULL (you do set it to something useful otherwise though.)

  3. #3
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Is it bad coding style?

    It's awful. Not only because of multiple variables (of different types, no less!) with meaningless names, but because they start with underscores. On top of that, no comments!

    If I had to guess... was this code machine generated?

  4. #4
    Join Date
    Jul 2008
    Location
    The Left Coast of the USA
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Is it bad coding style?

    Oh, c'mon.

    Who needs to write code so that it can be maintained by some poor schmoe that gets it dropped in his lap when you go to Cozumel for a month?

    Sheesh!
    Please read The Forum Rules and The Forum Posting Guidelines

    A thing discovered and kept to oneself must be discovered time and again by others. A thing discovered and shared with others need be discovered only the once.
    This universe is crazy. I'm going back to my own.

  5. #5
    Join Date
    Nov 2010
    Location
    Down the rabbit hole
    Beans
    435
    Distro
    Ubuntu Development Release

    Re: Is it bad coding style?

    Thanks anyone, it's actually code from unity-greeter, which I guess was written by folks from Canonical.
    Your ads here, just 9.99$/week !!

  6. #6
    Join Date
    Jul 2008
    Location
    The Left Coast of the USA
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Is it bad coding style?

    Someone needs to be spanked and sent to bed without supper!
    Please read The Forum Rules and The Forum Posting Guidelines

    A thing discovered and kept to oneself must be discovered time and again by others. A thing discovered and shared with others need be discovered only the once.
    This universe is crazy. I'm going back to my own.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •