• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Which is a better function name out of these as per the recommended naming convention?

 
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In python the function names should be in snake case.

If my function merges the current day data with past day data, I can name it as

merge_current_day_data_with_past_day_data

Or should I do it like

merge_currentDayData_with_pastDayData

The first one follows snake case but the second one is more readable.

Which one is the better way to name the functions ?

Thanks
 
Saloon Keeper
Posts: 8588
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java it would be
mergeCurrentDayDataWithPastDayData
 
Monica Shiralkar
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And in Python ?
 
Marshal
Posts: 22453
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Python uses snake case, so your merge_current_day_data_with_past_day_data is the recommended name.
 
Marshal
Posts: 16594
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
current day = today
past day = yesterday

I don't know if the word "data" is really needed. What does the data represent? That would probably be the better word/phrase to use in the name instead of just the generic "data" idea. I'd also think about a way to eliminate "today" and "yesterday" altogether from the name, maybe introduce parameters, if appropriate. If it's always today's and yesterday's data that are being merged, it might be better to leave that information out of the name and put in the documentation.

Additionally, I might ask what is the outcome of this merging of today's and yesterday's data? For example, add_current_day_total_with_past_day_total might just be calculate_weekly_running_total. Think at a higher level of abstraction and less at the implementation level when trying to find good names.
 
Saloon Keeper
Posts: 24314
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm all over the map with naming in Python myself (and apparently so are many library authors), but the one thing i generally avoid is mixing strategies. I'll either do c_like_names or javaLikeNames, but avoid mixed cases in c_like_names or underscores in javaLikeNames.
 
Monica Shiralkar
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

Junilu Lacar wrote: If it's always today's and yesterday's data that are being merged, it might be better to leave that information out of the name and put in the documentation.



Yes, I agree.

Junilu Lacar wrote:
I don't know if the word "data" is really needed. What does the data represent? That would probably be the better word/phrase to use in the name instead of just the generic "data" idea.



But should that not be in the context that what kind of data it is .E.g whether it is weather data or stocks data ?

Junilu Lacar wrote: For example, add_current_day_total_with_past_day_total might just be calculate_weekly_running_total.



But weekly data would mean data for the entire week instead of just data for today and yesterday.


Junilu Lacar wrote: Think at a higher level of abstraction and less at the implementation level when trying to find good names.



I was thinking that higher level part will be in the context so if I specify that in the name it may look unnecessary and long.


I understood that this name which I gave merge_currentDayData_with_pastDayData can be improved but what I want to know is that is that whether snake case and camel case mixed is also an acceptable format ?



 
Monica Shiralkar
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:but avoid mixed cases in c_like_names or underscores in javaLikeNames.



Thanks.

What I intended to by using is that in merge_currentDayData_with_pastDayData currentDayData and pastDayData are more together than merge and currentDayData and with and pastDayData, but there may be better ways to show this.


For e.g.  In function name write_processed_data , processed and data are more together than write and processed.

Is there a better way of showing this instead of using mixed cases like write_processedData
 
Junilu Lacar
Marshal
Posts: 16594
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:
But should that not be in the context that what kind of data it is .E.g whether it is weather data or stocks data ?


The name is what gives context. "data" is about as useful as "helper" and "manager" -- they are too generic and don't provide any meaningful context.
 
Monica Shiralkar
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
input_data , processed_data are relatively more meaningful than data.

I found currentDay_inputData (mixed of snake case and camel case) is easier to understand than current_day_input_data but the latter and not the former follows the python naming standards.
 
Sheriff
Posts: 8064
569
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd question also the design of the method.

Consider if that's the option you want to explore.
 
Liutauras Vilda
Sheriff
Posts: 8064
569
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd also add a comment to a method, what that merge means in this context, by providing an example.
 
Monica Shiralkar
Ranch Hand
Posts: 2512
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that the examples I came up with were not good.

The question that I intended to ask was whether mixing camel case and snake case is acceptable practice (in cases one thinks it is easier to understand).

As said above , one shouldn't be mixing cases and stick to snake case for python functions.

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic