Variadic Functions in Two Languages + Typesafe Variadic Logger
Context
Variadic functions accept a variable number of arguments. In systems and backend engineering, they appear in logging, formatting, and convenience APIs. This exercise asks you to compare how two languages support variadic functions and to implement an efficient, typesafe variadic logger that accepts key–value pairs.
Tasks
-
Choose two languages (e.g., C/C++, Go, Java, Python). For each language, explain:
-
What variadic functions are and the language syntax.
-
Calling conventions and how the callee accesses arguments.
-
Type-safety mechanisms (e.g., templates/generics vs raw varargs).
-
Performance and memory (stack/heap) implications.
-
How to forward variadic arguments to another function.
-
Implement a typesafe variadic logger that accepts key–value pairs and formats them efficiently.
-
Avoid format-string vulnerabilities and unnecessary boxing/reflection.
-
Provide a clean API for callers.
-
Show how to forward variadic arguments.
-
Discuss pitfalls, including:
-
Format-string vulnerabilities.
-
Boxing/reflection overhead.
-
Ambiguity resolution in overloads/dispatch.
-
Provide tests and analyze time/space complexity.