1. Home
  2. /
  3. D
  4. /
  5. Even Numbers Filter

Even Numbers Filter - D Typing CST Test

Loading…

Even Numbers Filter — D Code

Prints even numbers from an array.

import std.stdio;
void main() {
	int[] arr = [1,2,3,4,5];
	foreach(x; arr)
		if(x % 2 == 0)
		writeln(x);
}

D Language Guide

D is a high-level, statically typed, compiled systems programming language combining C-like performance with modern features like garbage collection, functional programming, and meta-programming.

Primary Use Cases

  • ▸Systems programming and OS-level development
  • ▸High-performance computing
  • ▸Game engines and graphics programming
  • ▸Financial and trading applications
  • ▸Compile-time code generation and metaprogramming

Notable Features

  • ▸C-like syntax familiar to C/C++ developers
  • ▸Garbage-collected memory with optional manual management
  • ▸Templates, mixins, and compile-time function execution
  • ▸Contracts, unit tests, and range-based algorithms
  • ▸Cross-platform compilation with high performance

Origin & Creator

Created by Walter Bright in 1999, later developed with contributions from Andrei Alexandrescu.

Industrial Note

D is used in performance-critical applications, game engines, high-performance computing, and financial software requiring fast, reliable code.

Quick Explain

  • ▸D supports imperative, object-oriented, and functional programming paradigms.
  • ▸It offers safe systems-level programming with modern abstractions.
  • ▸Templates, mixins, and compile-time reflection enable advanced metaprogramming.

Core Features

  • ▸Strong static typing with type inference
  • ▸Modules and package system
  • ▸Function overloading, operator overloading
  • ▸First-class functions and closures
  • ▸Compile-time reflection and code generation

Learning Path

  • ▸Learn basic syntax and control flow
  • ▸Understand structs, classes, and interfaces
  • ▸Explore templates and ranges
  • ▸Practice compile-time reflection and mixins
  • ▸Build real-world applications with Dub

Practical Examples

  • ▸Hello world CLI
  • ▸Range-based iteration example
  • ▸Template function for generic containers
  • ▸Class with inheritance and interfaces
  • ▸Compile-time mixin code generation

Comparisons

  • ▸Similar performance to C++
  • ▸Higher-level features than C/C++
  • ▸Easier syntax than C++ templates
  • ▸Smaller ecosystem than Rust or Go
  • ▸Better compile-time metaprogramming than most mainstream languages

Strengths

  • ▸High-performance native code
  • ▸Clean modern syntax with C-style familiarity
  • ▸Powerful compile-time metaprogramming
  • ▸Versatile multi-paradigm language
  • ▸Rich standard library with ranges and algorithms

Limitations

  • ▸Smaller community and ecosystem than C++ or Rust
  • ▸Less industrial adoption for large-scale projects
  • ▸Limited GUI library support
  • ▸Garbage collector can be unpredictable in real-time systems
  • ▸Interfacing with C++ can be complex

When NOT to Use

  • ▸Large-scale GUI-heavy desktop applications
  • ▸Projects needing massive library ecosystems
  • ▸Embedded systems with strict real-time constraints
  • ▸Rapid prototyping with minimal setup
  • ▸Applications requiring maximum portability with minimal compilation

Cheat Sheet

  • ▸import std.stdio;
  • ▸int x = 10;
  • ▸void main() { writeln("Hello World"); }
  • ▸struct S { int a; }
  • ▸template mixinExample() { ... }

FAQ

  • ▸Is D still relevant?
  • ▸Yes - used in high-performance and systems programming.
  • ▸Is D compiled or interpreted?
  • ▸Compiled to native binaries.
  • ▸Is D functional or imperative?
  • ▸Supports imperative, OOP, and functional paradigms.
  • ▸Can D be used for web development?
  • ▸Yes - via Vibe.d and other web libraries.

30-Day Skill Plan

  • ▸Week 1: Syntax, variables, functions
  • ▸Week 2: Classes, structs, inheritance
  • ▸Week 3: Templates, ranges, mixins
  • ▸Week 4: Performance tuning and concurrency

Final Summary

  • ▸D is a versatile systems programming language with high-performance and modern abstractions.
  • ▸Supports multi-paradigm development and compile-time metaprogramming.
  • ▸Ideal for system tools, games, web backends, and scientific computing.

Project Structure

  • ▸src/ - D source files
  • ▸tests/ - unit and integration tests
  • ▸dub.json - project configuration and dependencies
  • ▸examples/ - sample programs
  • ▸docs/ - project documentation

Monetization

  • ▸Game engine development
  • ▸High-performance computing tools
  • ▸Financial software
  • ▸Web backend services
  • ▸System utilities and CLI tools

Productivity Tips

  • ▸Use Dub for project and dependency management
  • ▸Write unittest blocks early
  • ▸Profile and optimize code iteratively
  • ▸Use templates/mixins for repetitive patterns
  • ▸Organize code with modules/packages

Basic Concepts

  • ▸Variables, constants, and types
  • ▸Functions and procedures
  • ▸Control flow: if, while, for, switch
  • ▸Structs, classes, and interfaces
  • ▸Modules, packages, and imports

Official Docs

  • ▸D Language Official Documentation
  • ▸D Language Reference
  • ▸Dub Package Manager Documentation

More D Typing Exercises

D Counter and Theme ToggleD Simple AdditionD FactorialD Fibonacci SequenceD Max of Two NumbersD Array SumD Conditional Counter IncrementD Resettable CounterD Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher