Naming conventions for _settings variables

Started by kelvincool, December 26, 2014, 10:56:24 AM

Previous topic - Next topic

kelvincool

Just wondering what everyone's naming convention is for mod variables in the settings table. Previously I had been doing things like this:

my_mod_my_variable_, etc...

What I evidently discovered was this doesn't work too well, mainly because the primary key is only indexed to 30 chars, so you are limited to 30 chars otherwise multiple variables get reset when you save  :-\

Looking at the table itself, there's a mix of camel case versus underscores so no real guide to follow there. I do like prefixing my variables with my mod name to avoid any conflicts but with that 30 limit it's quite difficult if your mod name is quite long. I suppose you could just use the initials?

Suki

I use camelCase, an acronym and a single underscore:

eiu_enable

eiu_someSetting

Where eiu stands for "Email Inactive Users".

Lately I use the name of my primary class so the name becomes uppercased:

ActivityBar_enable

ActivityBar_someSetting

Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

vbgamer45

Would it be bad to request that index length be increased for 2.1?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Suki

There are limitations depending on the DB type and usually keeping indexes as small as possible is a good thing.

Why would there be a need to use a variable name longer than 30 characters?  In all the time I've been creating mods I've never encountered a case where I would need more space.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

vbgamer45

I encountered it once before and this person here as well. Is there any reason why could be 50 at least?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Arantor

Because making it longer impacts every single call to updateSettings() in a negative way.

vbgamer45

We can't do it now but it wouldn't have been better if the variable name was limited to x amount of characters to prevent issues like this occurring then trying to figure out what is going on.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

kelvincool

Quote from: vbgamer45 on December 26, 2014, 03:00:03 PM
We can't do it now but it wouldn't have been better if the variable name was limited to x amount of characters to prevent issues like this occurring then trying to figure out what is going on.

It was certainly a head scratcher when I had the problem. Perhaps a tutorial on how to create mod administration pages and noted this sort of thing would help?

Suki

In order to do that, we need to know why  this is an issue, what was the cause that lead you to use a 30 or more chars name in a variable?

Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Night09

It could have been a Mary Poppins website and tried to add Supercalafajalistickespeealadojus_settings lol! :)

kelvincool

It's amazing how fast the characters run out when you define a variable for example:

my_module_plugin_default_value_1
my_module_plugin_default_value_2

Because I didn't know about the index being 30 characters I had no idea this was a problem. I learnt to do the mod settings by looking at existing code which obviously wouldn't have told me to keep my variable names to 30 chars.

I think overall it would be useful to have a tutorial on how to create these setting pages.

Suki

@kelvincool you have not answered my question.

Quote from: kelvincool on December 26, 2014, 03:50:34 PM
It's amazing how fast the characters run out when you define a variable for example:

It is not, like I said, in all the time I've been here, I haven't faced that issue, this is why I'm trying yo understand why this is an issue for you.

There is no mod by the name "my_module_plugin"  so this example isn't valid.

Why would you add the word "default" to any var name or the word "value"? the "value" is already implicit (and pretty explicit too) in the column name.

If your mod has a large name, use an acronym. An acronym/mod name plus a descriptive word for your setting is all you really need, thus I cannot see why there has to be an increase on the primary key length, specially if there is going to be performance issues.


Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

kelvincool

Quote from: Suki on December 26, 2014, 04:25:42 PM
@kelvincool you have not answered my question.

Quote from: kelvincool on December 26, 2014, 03:50:34 PM
It's amazing how fast the characters run out when you define a variable for example:

It is not, like I said, in all the time I've been here, I haven't faced that issue, this is why I'm trying yo understand why this is an issue for you.

There is no mod by the name "my_module_plugin"  so this example isn't valid.

Why would you add the word "default" to any var name or the word "value"? the "value" is already implicit (and pretty explicit too) in the column name.

If your mod has a large name, use an acronym. An acronym/mod name plus a descriptive word for your setting is all you really need, thus I cannot see why there has to be an increase on the primary key length, specially if there is going to be performance issues.

Sorry Suki, I wasn't asking for the index length to be increased, I was asking for a tutorial or some sort of wiki entry, I understand why it's set to 30 characters. Of course I would have just used "value" if I knew about the 30 character limit but I didn't and I wanted to be more precise in naming it.

Arantor

You don't need to use 'value'. Be descriptive.

For example, in my gallery I have things like lgal_comments_per_page - lgal is the prefix for all Levertine Gallery settings, after that I'm just descriptive.

As far as 'plugin' in the name goes, that's fairly explicit too as is 'value' as Suki said so in your example I'd start with my_module_default1 or similar. You've lost nothing in contextual terms compared to what you had before but it has no length issues.

Advertisement: