Is there a standard way to name a function which reads from a stream but does not advance the pointer? - naming-conventions

I can only think of Peek() and ReadNoAdvance() atm, but I wonder if there are better or standard options.
Thanks.

peek is the standard name, present in various languages.

I've seen ReadAhead(), but I think Peek() is more standard.

When writing parsers I've often also used lookahead.

Related

Rewrite this exceedingly long query

I just stumbled across this gem in our code:
my $str_rep="lower(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(field,'-',''),'',''),'.',''),'_',''),'+',''),',',''),':',''),';',''),'/',''),'|',''),'\',''),'*',''),'~','')) like lower('%var%')";
I'm not really an expert in DB, but I have a hunch it can be rewritten in a more sane manner. Can it?
It depends on the DBMS you are using. I'll post some examples (feel free to edit this answer to add more).
MySQL
There is really not much to do; the only way to replace all the characters is nesting REPLACE functions as it has already been done in your code.
Oracle DB
Your clause can be rewritten by using the TRANSLATE function.
SQL Server
Like in MySQL there aren't any functions similar to Oracle's TRANSLATE. I have found some (much longer) alternatives in the answers to this question. In general, however, queries become very long. I don't see any real advantages of doing so, besides having a more structured query that can be easily extended.
Firebird
As suggested by Mark Rotteveel, you can use SIMILAR TO to rewrite the entire clause.
If you are allowed to build your query string via Perl you can also use a for loop against an array containing all the special characters.
EDIT: Sorry I did not see you indicated the DB in the tags. Consider only the last part of my answer.
Your flagged this as Perl, but it's probably not?
Here is a Perl solution anyway:
$var =~ s/[\-\.\_\+\,\:\;\/\|\\\*\~]+//g;
Sorry I don't know the languages concerned, but a couple of things come to mind.
Firstly you could look for a replace text function that does more that just a single character. Many languages have them. Some also do regular expression based find and replace.
Secondly the code looks like it is attempting to strip a specific list of characters. This list may not include all that is necessary which means a relatively high (pain in the butt) maintenance problem. A simpler solution might be to invert the problem and ask what characters do you want to keep? Inverting like this sometimes yields a simpler solution.

Julia: how stable are serialize() / deserialize()

I am considering the use of serialize() and deserialize() for all of my data i/o due to their convenience. I do not, however, want to be stuck with unreadable files on a Julia update.
How stable are serialize() and deserialize()? Should they work between updates of 0.3? Can I expect safe behavior if I stick to basic types like arrays of Float64?
Thank you.
If you want to store data you might depend on being able to read in the future, you should not use a format that will incorporate breaking changes if/when someone finds it useful. As far as I understand the default serialization format is for network communications, so it is designed for maximum performance.
There is also the HDF5.jl package that uses a documented format and a common library that has wrappers for different languages.
I believe the official answer here is, "people will try not to break the serialization format, but you shouldn't depend upon on it."

Conditional Operator, is it appropriate?

I'm wondering, when is it appropriate to use conditional operators?
I've found I can use them an awful lot, and it really shortens the number of lines in my project but I worry that it makes my code harder to read for people I work with.
I know there's quite a few coding standard formats that people stick to and I was wondering if they made any mention of the use of conditional operators.
(a == b) ? true : false;
For the sake of Googling, you should know that this is often called the ternary operator.
Myself, I like them when they are short
var quantity_message = qty > 7 ? "enough" : "insufficient";
But I think they get hard to read very quickly as they get longer.
The common conventions such as the official Java conventions or Google's java conventions do not talk about whether to use ternary expressions, but have some comments on how to format them. I don't think anyone would ban them outright, but I'd be judicious.

How to use XBaseInterpreter in Xtext?

can someone tell me, how i can use "xbaseinterpreter"? I have no idea :(
I have written a DSL used to define simple protocol-structure for a sensornet, the goal of the work is to check if a data-message(as Instance) belongs to any user-defined structure. I want to use an interpret to analyze the user-defined structure and write the corresponding information into my database directly. I thought, xbaseinterpreter is just the one i can use, but i could not find much more useful information about it.
can one use the inferred JvmModel in the interpreter?How?
Thank you
See the tortoise language as a working example of how to use xbase and the interpreter.
http://eclipse.org/Xtext/documentation/208_tortoise.html

Variable name taken by keyword -- your examples?

Have there been any cases where you wanted to use a word as a variable/function name, but couldn't because it was a reserved word in your language?
The ones that crop up over and over again for me are in and out in C#... Those would be great names for streams, but I'm always forced to use inn and outt instead.
EDIT: I'm not asking about help with this problem -- I'm trying to learn from mistakes that past language designers have made. Your answers will influence a language I'm designing.
type and object. I don't like when my programming languages steal those :(
Some languages let you use any words you want anywhere. Clojure, for example:
(let [let "what?"] let)
=> "what?"
This could either be helpful or horrible depending on the context.
I like to use new and delete as function pointer fields in OO-ish C code a lot, which makes porting to C++ "fun"... ugh.
This isn't really a problem for C#, though:
int #in;
There, now you have a variable named in.
No, not really. Keywords in a language tend to be short and general - two things that rarely make for good variable names.
In those cases, I think of "in" and "out" as adjectives, and usually make something more descriptive, such as "inStream" and "outStream".