Is there a nice naming convention for nonempty lists in Haskell? [closed] - list

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 24 days ago.
This post was edited and submitted for review 24 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
For example, if I have a list of names names :: [Text], and I construct a NonEmpty Text from it, I could call it neNames, names', namesNonEmpty. Is there a standard (preferably short) convention for this?
A silly question, I know, but I'd like to know people's opinions on this. Naming is, after all, one of the two hard problems in computer science.
Edit: Apparently I'm not allowed to ask for people's opinions. However, the rest of the question still stands. Whether or not there is a standard convention for this is certainly something for which it is possible to provide citations.

Not that I'm aware of, but you might be able to borrow the convention from monadic parsers of using a 1 suffix to identify "at least one". We have sepBy and endBy when parsing zero or more things, and sepBy1 and endBy1 when parsing one or more things.
So, names and names1 might do it.
Ideally, you would try to design your datatypes so that you never have to name names at all, if an empty list of names indicates an invalid state, though I understand you might be validating an existing data structure where names can be empty into a new data structure where names1 must be non-empty.

Related

When is it better to use switch/case over if statements? [closed]

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 5 months ago.
This post was edited and submitted for review 5 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have a tendency to use switch statements if I am creating a menu driven program, and I tend to use if statements when I only have a few items. I believe this has to do with the way I was taught in school, but I don't know if that is necessarily the way to go.
Are there vast differences between the two? When should you pick one over the other?
Edit: I should specify, I am mainly concerned with optimization (even if one or the other is only marginally more efficient).
If statements look like if statements. Switch statements look like switch statements. Some compilers may be mildly better at optimizing certain types of switch statements than the equivalent set of if statements, though that won’t be a significant factor in your situations. In cases where the two are both applicable, there are few practical concerns in choosing one over the other.
Use whichever fits your intended coding style better.

Meaning of these particular pointers [closed]

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 3 years ago.
Improve this question
I'm hesitant to consider this a valid question so close or downvote if you wish, I promise not to be offended :-)
I've just been watching Herb Sutter's excellent CppCon2018 talk on making C++ more powerful and simpler at the same time. I'd strongly suggest watching this if you haven't already.
Near the end, he references an xkcd cartoon on pointers, where the three pointers given are suspiciously ASCII in nature(a), usually a sure sign that you've somehow got yourself a corrupt pointer.
The three pointers are 0x3a28213a, 0x6339392c and 0x7363682e, which equate to the three character blocks :(!:, c99, and sch. (though endian issues may reverse the order of the characters).
Does anyone know if there's any significance to these pointers?
(a) Yes, I also noticed the ASCII in Homer Simpson's 3d episode sequence, meaning I've been in this game way too long :-)

Clojure vs. Lisp: Why not concrete dotted pair in Clojure? [closed]

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 5 years ago.
Improve this question
In this discussion, a poster (mikera) says
There's no dotted pair in Clojure.
A philosophical reason for this is that Clojure avoids the use of a
concrete "pair" data structure and instead emphasises abstract
"sequences" which can have may possible concrete implementations.
Can someone elaborate or point me to some literature on what this means? Is this a more elegant or mathematically pure approach?
Here is a link to a handy list of questions that Rich has answered about his design decisions https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f
While this list doesn't explicitly explain why there is no concrete "pair" data structure it might give you some insight into Rich's preference for practical, general design.
I remember there was a time when there was a discussion about introducing a "tuple" which would have been like a vector that only has two elements to avoid the needless memory allocation that occurs when using a two element vector.
Introducing these things has a complexity cost and so you can assume that the cost/benefit analysis did not warrant adding it to the code base.
Check out this discussion on Clojure's Jira project about adding tuples and you'll see how any idea gets put through its paces:
https://dev.clojure.org/jira/browse/CLJ-1517

Should I make two versions of one program, each with different language, or add an option to change language? [closed]

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 5 years ago.
Improve this question
I have a program that I'm currently writing in English. In future, I would like to make the program multilingual, therefore I'm wondering what's the best option to do so. I thought about this two option for now:
Enable users to change language in settings;
Select the appropriate language while downloading;
With each option comes a problem:
A ton of code dedicated to displaying one message in different languages;
I will have to make many versions just to change the language of the displayed text;
Now my question is, which one of these options is more memory efficient and user friendly? Maybe neither of them are? Do you have any other option that is better than given two?
It is common to have an array or other structure, called something like strings, containing all the display strings your program will need. Instead of hardcoding messages into your program, you reference the array. To change language, you just alter the array.

Style and Enumerators [closed]

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
So, in the process of taking a data-structures class (in C++), my professor wanted us to manipulate a linked list of playing cards. That doesn't matter however, what I am interested in is why she did not use an enumerator to represent the suites.
In her code, she used strings to hold the suite of a card. This seemed inefficient because she wanted us to sort them based on suite, under the circumstances, it would have been considerably easier if she had used an enumerated type instead of a string. The string did not offer any help either, because in printing the suite, she output a Unicode character, roughly doubling the length of her function, simply because she did not use an enum.
Is there any reason for her to have done this, or does she simply have strange preferences when it comes to code style?
If you really want to know what your professor's reasoning is, you have to ask your professor. I can only speculate.
But if I were to speculate, I would guess that there are two possible reasons why your professor chose to use strings as descriptors for these attributes.
She is trying to keep the code simple and easy for newbie C++ programmers to understand. Whether the means meet the goal is debateable.
(Personal bias alert) Professors and others in academia, with no real-world experience, often do and teach things that I would consider to be highly sub-optimal.
My guess would be that she either had not considered that approach or that she wanted to test your ability to work with sorting strings.
Code examples might help in that they might clarify what she did and what you think she should have done.
The likely answer is that she just didn't think about the problem she was using to demonstrate whatever she is trying to teach you. That is, she wanted you to focus on sorting (for example), and probably took some code written by someone else and just adapted it to that purpose without much thought.