Questions tagged [templates]
126 questions
47
votes
9 answers
What did people do before templates in C++?
I am not new to programming, but I am one that started a few years ago, and I do love templates.
But in the before times, how did people deal with situations where they needed compile-time code generation like templates? I'm guessing horrible,…

IdeaHat
- 885
- 1
- 6
- 12
41
votes
3 answers
Why are C++ template error messages so horrific?
C++ templates are notorious for generating long, unreadable error messages. I have a general idea of why template error messages in C++ are so bad. Essentially, the problem is that the error isn't triggered until the compiler encounters syntax…

Channel72
- 2,475
- 5
- 27
- 28
35
votes
3 answers
where exactly should python business logic be placed in django
I have just begun to learn Django/Python/Web Development. This problem has been troubling me for a while now.
I am creating an application with multiple templates in Django. I have a views.py which is basically just rendering the responses to the…

adrita
- 355
- 1
- 4
- 7
30
votes
5 answers
Are C++ templates just a kind of glorified macros?
From different comparisons among C++ templates and C#/Java generics like this one-
https://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-and-java-and-templates-in-c/31929#31929
I got a perception that, C++…

Gulshan
- 9,402
- 10
- 58
- 89
29
votes
10 answers
Is template "metaprogramming" in Java a good idea?
There is a source file in a rather large project with several functions that are extremely performance-sensitive (called millions of times per second). In fact, the previous maintainer decided to write 12 copies of a function each differing very…

Fengyang Wang
- 400
- 3
- 8
22
votes
4 answers
What about LISP, if anything, makes it easier to implement macro systems?
I'm learning Scheme from the SICP and I'm getting the impression that a big part of what makes Scheme and, even more so, LISP special is the macro system. But, since macros are expanded at compile-time, why don't people make equivalent macro systems…

Elliot Gorokhovsky
- 607
- 6
- 13
21
votes
5 answers
Why C++ cannot adopt D's approach for its concept implementation?
As many of you guys know, concepts, C++'s approach for constraining possible types for a template argument has failed to be included in C++11.
I learned that the D programming language 2.0 has a similar feature for its generic programming. Its…

jj1
- 313
- 1
- 7
20
votes
9 answers
How to spread awareness for generic programming among team members?
I am staying in an environment, where people believe:
Java generics are the feature exclusively used for library writing
and not for the real coding.
C++ is an OO programming language; template is an optional and
avoidable feature
Though, these…

iammilind
- 2,232
- 4
- 24
- 35
16
votes
4 answers
C++ Preferred method of dealing with implementation for large templates
Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not work for template classes.
When looking online…

fhorrobin
- 271
- 2
- 6
16
votes
5 answers
How to structure template system using plain PHP?
I was reading this question over on stackoverflow:
https://stackoverflow.com/questions/104516/calling-php-functions-within-heredoc-strings
and the accepted answer says to do plain PHP templates like this:
template.php:
…

Ryan
- 1,645
- 2
- 15
- 24
15
votes
2 answers
How do I avoid writing lots of pass-through functions in a wrapper?
I have a class, which wraps another class of a common base type. Because the base type interface is quite large this involves writing a lot of pass-through functions. I am looking for a way to avoid this.
Let's make an example:
Car
/ …

Sarien
- 751
- 4
- 13
14
votes
3 answers
How do you handle increasingly long compile times when working with templates?
I use Visual Studio 2012 and he have cases where we added templates parameters to a class "just" in order to introduce a "seam point" so that in unit-test we can replace those parts with mock objects.
How do you usually introduce seam points in C++:…

Ghita
- 297
- 1
- 2
- 10
13
votes
4 answers
Should I include HTML markup in my JSON response?
In an e-commerce site, when adding an item to a cart, I'd like to show a popup window with the options you can choose. Imagine you're ordering an iPod Shuffle and now you have to choose the color and text to engrave.
I'd like the window to be…

Mike M. Lin
- 543
- 1
- 4
- 13
12
votes
2 answers
In C++, were SFINAE and metaprogramming intentional or just a byproduct of templates?
SFINAE and template metaprogramming can do wonderful things and many libraries also use them considerably.
Historically both of these "magic concepts" were intentionally introduced/supported in C++ ? Or they were just later discovered as useful…

iammilind
- 2,232
- 4
- 24
- 35
11
votes
1 answer
Way for generating C# classes from existing C# class
I have simple POCO classes, like this:
public class Book
{
public string BookId { get; set; }
public string Name { get; set; }
//etc...
}
I want to get all those classes and generate another classes, which called viewmodels, for…

Yurii N.
- 341
- 3
- 12