Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is necessary to call wordpress functions(in template) unique names? I think if I call them simple names, they may conflict with plugins(if user will install in future them). Is it true?
Sorry for stupid question..
you should read all naming conventions here http://code.tutsplus.com/articles/the-wordpress-coding-standards-naming-conventions-and-function-arguments--wp-31683
Function Names
As mentioned earlier, if classes are nouns that ideally represent a single idea or single purpose, then their methods should be the actions that they are able to take. As such, they should be verbs - they should indicate what action will be taken whenever they are called.
Furthermore, the arguments that they accept should also factor into the name of the function. For example, if a function is responsible for opening a file, then its parameter should be a file name. Since our goal should make it as easy as possible to read code, then it should read something like "have the local file manager read the file having the following file name."
Use lowercase letters in variable, action, and function names (never camelCase). Separate words via underscores. Don't abbreviate variable names un-necessarily; let the code be unambiguous and self-documenting.
Of course, there are always worse - some developers resort to using single characters for their variable names (which is generally only acceptable within loops.)
Just as the Coding Standards state: Don't abbreviate variable names un-necessarily. Let the code be unambiguous and self-documenting.
Now, the truth is, code can only be unambiguous to a point.
Anyway, the bottom line is to lower case your method names, avoid all camel casing, separate by spacing, and be as specific as possible when naming your variables and avoid duplicate names.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
So there's PRAGMA application_id meant to identify a SQLite database that is used as the file format of a program as this specific file format. The docs say one should choose a unique signed 32 bit integer for this and link https://www.sqlite.org/src/artifact?ci=trunk&filename=magic.txt as a list of registered types. But in this file, there are only a few entries.
So I have two questions:
Is it meaningful and common to actually run this pragma when using SQLite as the file format for a program?
If so, how should that number be chosen? Simply a random number? Or somehow derived from the program's name, homepage or whatever?
Edit:
In addition to the MikeT's answer, I want to add that using this feature, a file can be identified by the file (1) using a magic definition, also including the user_version. For e. g. 123 like so:
0 string SQLite\ format\ 3
>68 belong =int(0x0000007b) Program 123 file (using SQLite)
>>60 belong x \b, Version %d
which actually might be a nice use-case, as one can simply distinguish the file from a "plain" SQLite datase in this way.
Is it meaningful and common to actually run this pragma when using
SQLite as the file format for a program?
It is a rarely used feature and would only be meaningful to a specific application which would handle it in it's own way. It's basically a variable that can be set/changed to indicate to the specific application.
Say for example the application wanted to handle encrypted/non encrypted data the value could be set to indicate an encrypted database (or be a value to indicate one of a set of different encryption methods) or a non-encrypted, thus you could have a single easily and efficiently obtained value to determine which type.
Of course other methods could be used e.g. if the user_version isn't otherwise utilised that could be used.
If so, how should that number be chosen? Simply a random number? Or
somehow derived from the program's name, homepage or whatever?
The number, if used, should probably be set simply as it would need to be interpreted into a meaningful value. A random value would probably not be of any use.
In short it's a 4 byte field in the header that can be used as desired, similar to the user version field. However, it has the advantage that is less likely to alreadey be used, as an example if using the Android SDK/API's then the user_version is utilised for versioning and should not be used (or used with great care).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm not exactly sure what these modules are used for. I get that they split the respective url into its components, but why would that be useful, or what is an example of when to use urlparse?
Use urlparse only if you need parameter. I have explained below why do you need parameter for.
Reference
urllib.parse.urlsplit(urlstring, scheme='', allow_fragments=True)
This is similar to urlparse(), but does not split the params from the
URL. This should generally be used instead of urlparse() if the more
recent URL syntax allowing parameters to be applied to each segment of
the path portion of the URL (see RFC 2396) is wanted.
Hostname is always useful to store in variable to use it later or adding parameter, query to hostname to get the web page you want while scraping.
Regarding Parameter:
FYI: According to RFC2396, parameter in url
Extensive testing of current client applications demonstrated that the
majority of deployed systems do not use the ";" character to indicate
trailing parameter information, and that the presence of a semicolon
in a path segment does not affect the relative parsing of that
segment. Therefore, parameters have been removed as a separate
component and may now appear in any path segment. Their influence has
been removed from the algorithm for resolving a relative URI
reference.
Parameter are useful in scraping,
e.g. if the url is http://www.example.com/products/women?color=green
When you use urlparse, you will get parameter. Now You have to change it to men so it will be http://www.example.com/products/men?color=green and kids, girl, boy so on.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
How can I set the default language based on Country and/or keyboard using the sitecore framework?
I take your point that you would expect an out of the box solution, but in fact the requirements are often perculiar to the project. That said, here are some thoughts
Creating a custom language resolver is probably the best approach.
First Attempt
I normally start by trying to use the the browser language preferences (HttpRequest.UserLanguages), which might supply the whole 2-part language 'en-GB', or sometimes just the basic language 'en'.
If this gave you the whole language, then your're done. Just get the system language with the with the same name.
If it gave you the basic language only, you need to get the country somehow.
If it didn't give you anything. You need to get the country, and find a default language for that country.
Getting the Country
If you go with the MaxMind option, you should probably use the the GeoLite version locally, as you can't rely on the DMS Geo IP lookup being performed in a timely manner.
If the lookup is successful, and you already had a basic language then you should now have 2-part language to compare against your system languages.
If the lookup was successful, but you don't have basic language, then you need to get a default. In the past, I have created a 'Language Mapping' template with 2 fields. A 'Country code' text field, and a 'Language' droplink source to the list of system language. When you have obtained the country code, you simply look it up in your mapping items, and set the context language accordingly.
Some things to consider
Remember you need to have some sort of fallback for when the lookups haven't worked.
Perhaps store the language as a cookie, so the lookup is not done every time.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Background:
I'm begining to forge my way into more of a software engineering role at work. I have no computer science background and have learned to program some high level languages on my own (mostly R, python, and ruby). And before I start to find my own solutions to problems, I want to know best practices for keeping tack of last runs of the program.
Specifically, I'm writing a program that will clean data in a database (find missing data, imputation, etc...). It needs to know when it was last run so it does not retrieve too much data.
Question:
How do I best keep track of previous code runs?
I'm writing production level code. These scripts and functions will be run automatically (maybe a nightly or weekly basis), and the results will be output to a file. Each of these programs will depend on when it was run last. I can see this dealt with a few ways.
The output file name (or a diagnostic file name) contains the last date/time it was run. I.e. 'output_file_2014_07_11_01_00_04.txt' From this name, the program can determine when it was last run.
Keep a separate info file that the program just appends the last run time to a list of run times.
These solutions seem prone to problems. Is there a more secure and efficient method for recording/reading the last run date?
I like the idea of putting it in the filename. That binds the run time to the actual data. If you keep the run time in a separate file, data can separated from the meta-data (i.e. the run time).
This works in a trusted environment. If accidental or malicious vandalism is a concern, like changing a filename is a problem, then a lot other things become problematic too.
A third alternative is to create a "header" or comment section in the data file itself. The the run time in the header. When you read the data, your skip can either skip the header and go straight for the data, or examine the header and extract the meta-data (i.e. run time or other attributes).
This approach has the advantage that (a) the meta-data and the data are kept together and (b) you can include more meta-data than just the run time. This approach has the disadvantage that any program reading the data must first skip the header. For an example of this approach, see the Attribute-Relation File Format (ARFF) at http://www.cs.waikato.ac.nz/ml/weka/arff.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Since initially running package.skeleton to create a package, I have added several S3 classes. Each of these classes has 5-10 methods. I've discovered the wonderful prompt command to create .Rd files from a function loaded into memory, but is it possible to have R automagically create a single help file that has all multiple functions documented? I'm thinking of something like an enhanced version of prompt where you would pass it a list of functions, and it would create a single .Rd file with only the additional information added to the help file.
For instance, if I have a generic called duration, and classes for which there are methods duration.bond(market,...), duration.account(market,time,...), duration.portfolio(market,...), I would like prompt to create a helpfile with a \usage section containing each \method{} and an \arguments{} section containing market,\dots, and time.
Any hope here? Copying and pasting is getting very tiring!
For completeness, adding in what I chose to do here, which is to pick the method that has the most arguments and use prompt on that, then add in the other methods manually to the same help file.
The other alternative would have been to use Rd2roxygen to convert everything that was already in .Rd back to Roxygen and then use Roxygen for the whole project. This will likely be what I do in the next release.
You could roll-your-own by reading in a template help file (with readLines), then editing it to suit each particular case (judicious use of paste and gsub), then writing the result back out to file (via writeLines).