Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 2550
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: 8770
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: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And in Python ?
 
Sheriff
Posts: 22511
122
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.
 
Sheriff
Posts: 16706
278
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: 24586
168
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: 2550
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: 2550
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
Sheriff
Posts: 16706
278
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: 2550
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.
 
Marshal
Posts: 8144
572
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
Marshal
Posts: 8144
572
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: 2550
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
 
Rancher
Posts: 187
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote: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.


I don't know python, but no matter the language your way of comming up with mames looks weird to me.

If you have some inpu, just call it that: input
If you have some processed output, just call it that: output

As for your question: I would simply call it merge and the two input would simply be yesterday and today: output = merge(yesterday, today)
Same with your write function: write(output)
There's no need to add "data" to anything in any case. I can only imagine what the rest of your identifiers look like.
 
Monica Shiralkar
Ranch Hand
Posts: 2550
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Bendford wrote: your write function: write(output)
There's no need to add "data" to anything in any case.



So means name it simply like write(output) when "where to write" is obvious only when we have write_to_s3 and write_to_dynamodb then we should be giving bigger names to differentiate  as we can't differentiate between the two in this case by simply saying write?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic