Questions tagged [library-design]

Use this tag for topic related to library development

Relates to designing and developing libraries, which can be used for private or public software development.

66 questions
7
votes
2 answers

val or object for immutable, final singleton object

Which solution should be generally preferred, considering that the change is source compatible? This object Foo { val Bar = new Baz(42, "The answer", true) } or this? object Foo { object Bar extends Baz(42, "The answer", true) }
soc
  • 27,983
  • 20
  • 111
  • 215
7
votes
1 answer

What purpose does `gsl::string_span` aim at?

During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions: Why is gsl::string_span provided where gsl::span already works well? Why is gsl::zstring_span provided where std::string is already guaranteed to be…
szxwpmj
  • 465
  • 2
  • 10
7
votes
2 answers

Implementing copy and move assignment with a single function

Typically, given some type T, to implement copy and move assignment, one needs two functions T& operator=(T&&) { ... } T& operator=(const T&) { ... } Recently, I come to realize that a single one is just sufficient T& operator=(T v) { swap(v); …
Lingxi
  • 14,579
  • 2
  • 37
  • 93
7
votes
0 answers

Why 'Unknwn.h' instead of 'Unknown.h'? Is it misprint?

Why is Microsoft's COM header file named as Unknwn.h, instead of Unknown.h? Is it misprint, or are there objective reasons for such naming?
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
6
votes
2 answers

Why is 'this' in jquery chaining callbacks a DOM element?

So I know that when using $.fn.each, $.fn.bind, etc, it is standard for the this keyword within jQuery chaining callbacks to be a DOM element. I know in my development at least I usually want the DOM element wrapped in a jQuery set - 90% of the time…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
6
votes
1 answer

What's the purpose of $scope in scala.Predef?

scala.Predef contains the following code: // Apparently needed for the xml library val $scope = scala.xml.TopScope Did someone figure out why it is necessary, considering that it creates dependencies to packages which could have been easily split…
soc
  • 27,983
  • 20
  • 111
  • 215
6
votes
1 answer

Compose C header file to be able to be used from C++

I'm working on some library header file that is supposed to be used from both C and C++. Since C does not have a namespace concept I would add a "library prefix" to all names defined in the header file. By contrast, for C++ I would define a…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
6
votes
6 answers

Why is the java.lang.Thread class in Java not marked final by the designers?

What is the essence of allowing the user to create thread by extending the Thread class when we can achieve the same functionality by implementing Runnable and pass it to the Thread constructor.
6
votes
1 answer

Scala: package object v.s. singleton object within a package

I want to group a set of similar functions in a library in scala. Here are two approaches I have seen elsewhere. I want to understand the differences between the two. Singleton object defined in a package //…
Nik
  • 170
  • 10
6
votes
2 answers

How should I build a simple database package for my python application?

I'm building a database library for my application using sqlite3 as the base. I want to structure it like so: db/ __init__.py users.py blah.py etc.py So I would do this in Python: import db db.users.create('username',…
Carson Myers
  • 37,678
  • 39
  • 126
  • 176
5
votes
2 answers

Raise compile-time error if a string has whitespace

I have a base class that is intended to be inherited by other users of the code I'm writing, and one of the abstract functions returns a name for the object. Due to the nature of the project that name cannot contain whitespace. class MyBaseClass { …
Michael Hoffmann
  • 2,411
  • 2
  • 24
  • 42
4
votes
1 answer

Why the std::this_thread namespace?

Is there a technical reason for the std::this_thread namespace? Why could the members of this namespace not have been implemented as static members of the std::thread class?
user2100815
4
votes
5 answers

A couple of questions regarding on OO and library design

Ok. I have some questions regarding to some aspects of OO, and library design. Should a library be self-sufficient? Eg., can it use an external Dependency Injection framework, or should it implement it own, in a more lightweight manner? How does…
user1130159
3
votes
3 answers

Why don't C++03 file streams accept string constructor parameters?

Why does the following code compile in C++11 and does not in C++03? (both gcc and cl) #include #include #include int main(int argc, char* argv[]) { const std::string t("Hello"); std::ofstream out(t); } Why…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
3
votes
1 answer

Why does RegexTest have a main method?

I wonder why scala.util.parsing.combinator.testing.RegexTest has a main method. Aren't library classes intended to be called from within the program and not run separately as an independent executable?
soc
  • 27,983
  • 20
  • 111
  • 215