forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecate.dd
991 lines (856 loc) · 29.1 KB
/
deprecate.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
Ddoc
$(SPEC_S Deprecated Features,
$(P Sometimes it becomes clear that a feature is just a bad idea.
These are called $(I deprecated features) and once they are judged
to merit removal from the language, they follow a procedure in
order to allow plenty of time for users to adjust to the change.
)
$(TABLE2 Deprecated Features,
$(THEAD Feature, Spec, Dep, Error, Gone)
$(TROW $(DEPLINK body keyword), 2.075, , , )
$(TROW $(DEPLINK Hexstring literals), 2.079, 2.079, 2.086, )
$(TROW $(DEPLINK Class allocators and deallocators), , 2.080, 2.087, )
$(TROW $(DEPLINK Implicit comparison of different enums), 2.075, 2.075, 2.081, )
$(TROW $(DEPLINK Implicit string concatenation), 2.072, 2.072, 2.081, )
$(TROW $(DEPLINK Using the result of a comma expression), 2.072, 2.072, 2.079, )
$(TROW $(DEPLINK delete), , 2.079, , )
$(TROW $(DEPLINK scope as a type constraint), , 2.087, , )
$(TROW $(DEPLINK Imaginary and complex types), future, , , )
$(TROW $(DEPLINK Implicit catch statement), 2.072, 2.072, 2.081, )
$(TROW $(DEPLINK .sort and .reverse properties for arrays), ?, 2.072, , 2.075)
$(TROW $(DEPLINK C-style array pointers), ?, 2.072, 2.082, )
$(TROW $(DEPLINK Floating point NCEG operators), 2.079, 2.066, 2.072, 2.080 )
$(TROW $(DEPLINK clear), 2.060, 2.066, , 2.068 )
$(TROW $(DEPLINK .min property for floating point types), N/A, 2.065, 2.067, 2.072 )
$(TROW $(DEPLINK Cast T[] to integral type), ?, 2.060, , 2.061 )
$(TROW $(DEPLINK Base Class Protection), 2.058, 2.058, 2.067, 2.072 )
$(TROW $(DEPLINK Windows 3.x and Windows 9x support), 2.058, N/A, N/A, 2.058 )
$(TROW $(DEPLINK typedef), 2.057, 2.057, 2.067, 2.072 )
$(TROW $(DEPLINK Using * to dereference arrays), ?, 2.057, 2.067, (never) )
$(TROW $(DEPLINK invariant as an alias for immutable), 2.057, 2.057, 2.064, 2.066 )
$(TROW $(DEPLINK Non-final switch statements without a default case), 2.054, 2.054, 2.068, (never) )
$(TROW $(DEPLINK Hiding base class functions), 2.054, 2.054, 2.068, (never) )
$(TROW $(DEPLINK Octal literals), 2.054, 2.053, 2.067, (never) )
$(TROW $(DEPLINK C-style function pointers), ?, 2.050, 2.067, (never) )
$(TROW $(DEPLINK Using length in index expressions), ?, 2.041, , 2.061 )
$(TROW $(DEPLINK Escape string literals), ?, 2.026, 2.061, 2.067 )
$(TROW $(DEPLINK volatile), 2.013, 2.013, 2.067, 2.072)
$(TROW $(DEPLINK HTML source files), ?, 2.013, N/A, 2.061 )
$(TROW $(DEPLINK Overriding without override), ?, 2.004, 2.072, (never) )
$(TROW $(DEPLINK Lower case 'l' suffix for integer literals), ?, 1.054, 0.174, (never) )
$(TROW $(DEPLINK Variable shadowing inside functions), ?, 0.161, , 2.061 )
$(TROW $(DEPLINK Upper case 'I' suffix for imaginary literals), ?, 0.154, 2.061, (never) )
$(TROW $(DEPLINK if (v; e)), ?, 0.149, 2.061, 2.068 )
$(TROW $(DEPLINK Removing an item from an associative array with delete), ?, 0.127, 2.061, 2.067 )
$(TROW $(DEPLINK .offset property), ?, 0.107, 2.061, 2.067 )
$(TROW $(DEPLINK .size property), ?, 0.107, 0.107, 2.061 )
$(TROW $(DEPLINK .typeinfo property), ?, 0.093, 2.061, 2.067 )
)
$(DL
$(DT Spec)
$(DD Removal from the Specification)
$(DT Dep)
$(DD The compiler warns by default, issues an error with the -de switch, and can be silenced with the -d switch)
$(DT Error)
$(DD It is an error to use the feature)
$(DT Gone)
$(DD The feature is completely gone)
)
$(H3 $(DEPNAME body keyword))
$(P 'body' was a keyword used to specify a function/method's body in the presence of contracts
---
class Foo
{
void bar(int i)
in { assert(i >= 42); }
body { /* Do something interesting */ }
string method(string s)
out(v) { assert(v.length == s.length); }
body { /* Do something even more interesting */ }
void noBody() { /* No contracts, no body */ }
}
---
)
$(H4 Corrective Action)
$(P Use the 'do' keyword instead (introduced v2.075.0)
---
void bar(int i)
in { assert(i >= 42); }
do { /* Look ma, no body! */ }
---
)
$(H4 Rationale)
$(P The 'body' keyword was only used for this single purpose.
Since D grammar aims to be context free, this common word was reserved,
which led to frequent trouble for people interfacing with other languages
(e.g. javascript) or auto-generating code.
)
$(P Note that given the large amount of code relying on the 'body' keyword
(essentially any code using contracts), and the fact that the benefit
of DIP1003 to the user are mostly the ability to use 'body' as an identifier,
the deprecation has been postponed beyond its original goal of 2.091.0.
Users are still encouraged to use 'do' for future-proofness.
)
$(H3 $(DEPNAME Hexstring literals))
$(P Hexstring literals can be used to enter literals in base 16.
---
// deprecated code
// auto x = x"1234";
---
)
$(H4 Corrective Action)
$(P Use the $(REF hexString, std,conv) template.
---
auto x = hexString!"1234";
---
)
$(H4 Rationale)
$(P Hexstrings are used so seldom that they don't warrant a language feature.
)
$(H3 $(DEPNAME Class allocators and deallocators))
$(P D classes can have members customizing the (de)allocation strategy.
---
class Foo
{
new(uint size, ...)
{
return malloc(size);
}
delete(void* obj)
{
free(obj);
}
}
Foo foo = new(...) Foo();
delete foo;
---
)
$(H4 Corrective Action)
$(P Move the (de)allocation strategy out of the class
---
class Foo
{
}
T make(T, Args...)(auto ref Args args) if (is(T == Foo))
{
enum size = __traits(classInstanceSize, T);
void* mem = malloc(size);
scope (failure) free(mem);
return mem !is null ? emplace!T(mem[0..size], args) : null;
}
void dispose(T)(T obj)
{
auto mem = cast(void*) obj;
scope (exit) free(mem);
destroy(obj);
}
Foo foo = make!Foo();
if (foo !is null) dispose(foo);
---
)
$(H4 Rationale)
$(P Classes should not be responsible for their own (de)allocation strategy.
)
$(H3 $(DEPNAME Implicit comparison of different enums))
$(P Comparison of different enumerated type was allowed:
---
enum Status
{
good,
bad
}
enum OtherStatus
{
ok,
no
}
static assert(Status.good == OtherStatus.ok);
---
)
$(H4 Corrective Action)
$(P Comparison between unrelated enumerated types should be done with $(REF asOriginalType, std, conv))
---
import std.conv : asOriginalType;
assert(Foo.x.asOriginalType == Bar.y.asOriginalType);
---
$(H4 Rationale)
$(P Code correctness is improved by
disallowing comparison of unrelated enumerated types. Implicit comparison of
different `enum` types often resulted in hard to spot bugs.)
---
enum { X }
enum { Y }
void main() {
auto b = X == Y;
assert(b);
}
---
$(H3 $(DEPNAME Implicit string concatenation))
$(P Two adjacent strings were implicitly concatenated:
---
string foo = "Hello" "World";
---
This feature was handy for a long string that spans multiple lines,
however, it is possible to get the same behaviour explicitly by
using the concatenation operator ('~'):
---
string foo = "Hello" ~ "World"; // No allocation is performed
---
)
$(H4 Corrective Action)
$(P Replace implicit string concatenation by explicit one, using '~'.)
$(H4 Rationale)
$(P This is a very early feature of the language, which is nowadays totally
covered by the concatenation operator: it is performed at compile time
for constants and doesn't result in memory allocation.)
$(P However, having implicit concatenation can and did result in hard
to spot bugs, for example:)
---
string[] names =
[
"Anna",
"Michael"
"Emma",
"David"
];
// The content of arr is [ "Anna", "MichaelEmma", "David" ]
---
$(H3 $(DEPNAME Using the result of a comma expression))
$(P The comma operator (`,`) allows executing multiple expressions and
discards the result of them except for the last which is returned.
---
int a = 1;
int b = 2;
bool ret = a == 2, b == 2; // true
---
It's also common to use the comma operator in for-loop increment
statements to allow multiple expressions.
---
for (; !a.empty && !b.empty; a.popFront, b.popFront)
---
)
$(H4 Corrective Action)
$(P If possible, split the comma operator in two statements. Otherwise use
lambdas.
---
auto result = foo(), bar();
// split off in two statements
foo();
auto result = bar();
// or use lambdas
auto result = {foo(); return bar();}();
---
)
$(H4 Rationale)
$(P The comma operator leads to unintended behavior (see below for a selection)
Moreover it is not commonly used and it blocks the ability to implement tuples.
A selection of problems through the accidental use of the comma operator:
---
writeln( 6, mixin("7,8"), 9 ); // 6, 8, 9
template vec(T...)(T args) { ... }
vec v = (0, 0, 3); // 3, because vec is variadic
int b = 2;
if (a == 1, b == 2) {
// will always be reached
}
void foo(int x) {}
foo((++a, b));
synchronized (lockA, lockB) {}
// isn't currently implemented, but still compiles due to the comma operator
---
)
$(H3 $(DEPNAME delete))
$(P Memory allocated on the GC heap can be freed with $(D delete).
---
auto a = new Class();
delete a;
---
)
$(H4 Corrective Action)
$(P Use $(LINK2 phobos/object.html#.destroy, $(D object.destroy()))
to finalize the object instead.
---
auto a = new Class();
destroy(a);
---
)
$(P Note that $(D destroy) does not free the allocated memory. If
necessary, call $(LINK2 phobos/core_memory.html#.GC.free, $(D core.GC.free)) also.
)
$(H4 Rationale)
$(P $(D delete) makes assumptions about the type of garbage collector
available that limits which implementations can be used, and can be
replaced by a library solution.
)
$(H3 $(DEPNAME scope as a type constraint))
$(P
The `scope` keyword can be added to a class declaration to force all instances of the
class to be attributed with the `scope` storage class.
---
scope class C { } // `scope` type constraint. This usage of `scope` is deprecated.
void main()
{
C c1 = new C(); // Error: reference to `scope class` must be `scope`
// This error is due to the `scope` attribution on the declaration
// of `class C` and the missing `scope` storage class attribution
// on `c1`.
scope C c2 = new C(); // OK because the instance `c2` is attributed with the `scope`
// storage class. This usage of `scope` is not deprecated.
}
---
)
$(H4 Corrective Action)
There is no current counterpart in the D programming language or library that places such a
constraint on a type requiring all instances of the type to be attributed with the `scope`
storage class.
$(H4 Rationale)
$(P
`scope` as a type constraint was a quirk in the language without a compelling
use case.
)
$(P
Note that this deprecation only affects the usage of `scope` as a type constraint
attributed to a class declaration. `scope` as a storage class attributed to variables,
function parameters, etc. is not deprecated.
)
$(H3 $(DEPNAME Imaginary and complex types))
$(P D currently supports imaginary and complex versions of all floating point types.
---
float a = 2;
ifloat b = 4i;
cfloat c = a + b;
assert(c == 2 + 4i);
---
)
$(H4 Corrective Action)
$(P Use the library types in $(STDFILEREF complex).
)
$(H4 Rationale)
$(P These types are too specialized to be a part of the core language.
)
$(H3 $(DEPNAME Implicit catch statement))
$(P One can catch everything by using $(D catch) without specifying a type.)
---
int[] arr = new int[](10);
// This will throw a RangeError
try { arr[42]++; }
catch { writeln("An error was caught and ignored"); }
---
$(H4 Corrective Action)
$(P Either don't catch `Throwable` or replace `catch {}` with `catch (Throwable) {}`)
---
int[] arr = new int[](10);
// This will throw a RangeError
try { arr[42]++; }
catch (Throwable) { writeln("An error was caught and ignored"); }
---
$(H4 Rationale)
$(P Catching `Throwable` should not be encouraged by the language,
because certain core guarantee cannot be satisfied, e.g. the stack might not get cleaned
up and destructors might not get run.
This change helps ensure catching `Throwable` is always a conscious and visible decision
on the programmer's side.
)
$(H3 $(DEPNAME .sort and .reverse properties for arrays))
$(P D arrays can be manipulated using these built-in properties.
---
int[] x = [2, 3, 1];
assert(x.sort == [1, 2, 3]);
---
)
$(H4 Corrective Action)
$(P Use the generic functions in $(STDFILEREF algorithm).
)
$(H4 Rationale)
$(P These operations are better implemented in the standard library.
)
$(H3 $(DEPNAME C-style array pointers))
$(P C-style array pointers can be used in D.
---
alias float *arrayptr[10][15];
---
)
$(H4 Corrective Action)
$(P Replace with D-style array pointers.
---
alias float[15][10]* arrayptr;
---
)
$(H4 Rationale)
$(P The D syntax is much cleaner and easier to use.
)
$(H3 $(DEPNAME Floating point NCEG operators))
$(P D currently supports the NCEG floating point operators
(!<>=, <>, <>=, !>, !>=, !<, !<=, !<>) for comparisons involving NaNs.
)
$(H4 Corrective Action)
$(P Use the normal operators and $(REF isNaN, std,math).
)
$(H4 Rationale)
$(P These operators are too specialized to be a part of the core language.
)
$(H3 $(DEPNAME clear))
$(P Call an object's destructor.
---
auto a = new Class();
clear(a);
---
)
$(H4 Corrective Action)
$(P Use $(LINK2 phobos/object.html#.destroy, $(D object.destroy())) instead.
---
auto a = new Class();
destroy(a);
---
)
$(H4 Rationale)
$(P Due to Uniform Function Call Syntax (UFCS), $(D clear) can cause
confusion with other methods of the same name, such as a $(D clear)
method used to remove the contents of a container.
)
$(H3 $(DEPNAME .min property for floating point types))
$(P Floating point types have the .min property to access the smallest value.
---
enum m = real.min;
---
)
$(H4 Corrective Action)
$(P Replace with .min_normal
---
enum m = real.min_normal;
---
)
$(H4 Rationale)
$(P The name min_normal is more accurate, as .min does not include
denormalized floating point values.
)
$(H3 $(DEPNAME Cast T[] to integral type))
$(P At some point in time you could do:
---
ulong u = cast(ulong)[1,2];
---
To get the length of the array.
)
$(H4 Corrective Action)
$(P Use the $(LINK2 https://dlang.org/spec/arrays.html#array-properties, .length)
property instead.
)
$(H4 Rationale)
$(P Using a cast to get the length of an array is just confusing.
)
$(H3 $(DEPNAME Base Class Protection))
$(P Base class protections are things like:
---
class A : $(D protected) B
{
...
}
---
)
$(H4 Corrective Action)
$(P Delete the protection attribute keyword from in front of the base class
and base interfaces.
)
$(H4 Rationale)
$(P With D's module system, it doesn't seem to serve any useful purpose, and
has never worked correctly.
)
$(H3 $(DEPNAME Windows 3.x and Windows 9x support))
$(P There is some code in Phobos for Windows 3.x/9x support.
)
$(H4 Corrective Action)
$(P Upgrade Windows or switch to another supported OS.
)
$(H4 Rationale)
$(P Supporting such outdated and rarely used OS-es isn't worth the trouble.
)
$(H3 $(DEPNAME typedef))
$(P typedef can be used to construct a strongly-typed alias of a type.
---
typedef int myint;
static assert(!is(myint == int));
---
)
$(H4 Corrective Action)
$(P Replace use of typedef with alias or use $(REF Typedef, std,typecons).
)
$(H4 Rationale)
$(P typedef is not flexible enough to cover all use cases. This is better
done with a library solution.
)
$(H3 $(DEPNAME Using * to dereference arrays))
$(P D array variables can be dereferenced to get the first element, much like pointers.
---
int[] arr = [1, 2, 3];
assert(*arr == 1);
---
)
$(H4 Corrective Action)
$(P Use indexing syntax to access first member.
---
int[] arr = [1, 2, 3];
assert(arr[0] == 1);
---
)
$(H4 Rationale)
$(P D arrays are not pointers.
)
$(H3 $(DEPNAME invariant as an alias for immutable))
$(P The invariant storage class and type modifier is an alias for immutable.
---
static assert(is(invariant(int) == immutable(int)));
---
)
$(H4 Corrective Action)
$(P Replace all uses of invariant as a storage class or type modifier with
immutable. The invariant() syntax for struct and class invariants is
still supported.
)
$(H4 Rationale)
$(P The alias is unnecessary.
)
$(H3 $(DEPNAME Non-final switch statements without a default case))
$(P Switch statements can be declared without a default case, and the
compiler automatically adds one.
---
switch(a)
{
case 1:
break;
case 2:
break;
// the compiler adds
// default:
// throw new SwitchError();
}
---
)
$(H4 Corrective Action)
$(P Add the default case manually.
---
switch(a)
{
case 1:
break;
case 2:
break;
default:
assert(0);
}
---
)
$(H4 Rationale)
$(P Missing default cases can hide bugs, and making the default case
explicit should be mandatory.
)
$(H3 $(DEPNAME Hiding base class functions))
$(P This occurs when declaring a function in a derived class that can be called with the
same arguments as a function in a base class, without overriding that
function. The base class function gets hidden:
---
class A
{
void fun(int x) {}
}
class B : A
{
void fun(long x) {}
}
---
)
$(H4 Corrective Action)
$(P Add the function to the base class, or use an alias to bring the base
class overload into the derived class:
---
class A
{
void fun(int x) {}
void fun(long x) {} // this fixes it
}
class B : A
{
void fun(long x) {}
alias A.fun fun; // so does this
}
---
)
$(H4 Rationale)
$(P This is an error that is already detected at runtime, and is being
extended to compile time.
)
$(H3 $(DEPNAME Octal literals))
$(P Octal literals can be used to enter literals in base 8.
---
// deprecated code
// auto x = 0123;
---
)
$(H4 Corrective Action)
$(P Use the $(REF octal, std,conv) template.
---
auto x = octal!123;
---
)
$(H4 Rationale)
$(P The use of a leading zero is confusing, as 0123 != 123.
)
$(H3 $(DEPNAME C-style function pointers))
$(P C-style function pointers can be used in D.
---
alias void(*fptr)(int, long);
---
)
$(H4 Corrective Action)
$(P Replace with D-style function pointers.
---
alias void function(int, long) fptr;
---
)
$(H4 Rationale)
$(P The D syntax is much cleaner and easier to use.
)
$(H3 $(DEPNAME Using length in index expressions))
$(P When used inside an indexing or slicing expression, length is rewritten to
be the length of the array being sliced.
---
auto a = new int[5];
a = a[0..length-1];
---
)
$(H4 Corrective Action)
$(P Replace length with the equivalent $(LINK2 spec/arrays.html#array-length, '$')
)
$(H4 Rationale)
$(P The implicitly defined length variable shadows existing declarations,
and is less concise than the alternative.
)
$(H3 $(DEPNAME Escape string literals))
$(P Escape string literals can be used to describe characters using escape sequences.
---
// deprecated code
// string x = "hello" ~ \n;
---
)
$(H4 Corrective Action)
$(P Put escape sequences inside a regular string literal.
---
string x = "hello\n";
---
)
$(H4 Rationale)
$(P Escape string literals are unintuitive and unnecessary.
)
$(H3 $(DEPNAME volatile))
$(P volatile can be used to mark statement, in order to prevent some
compiler optimizations.
---
volatile
{
... do something involving ghared variables ...
}
---
)
$(H4 Corrective Action)
$(P Convert the code to use synchronized statements instead.
)
$(H4 Rationale)
$(P volatile statements are a misfeature.
)
$(H3 $(DEPNAME HTML source files))
$(P The D compiler can parse html files by ignoring everything not contained
in <code></code> tags.
---
<html>
<code>
... source ...
</code>
</html>
---
)
$(H4 Corrective Action)
$(P Extract code to regular source files.
)
$(H4 Rationale)
$(P This has been replaced for documentation by the introduction of ddoc
)
$(H3 $(DEPNAME Overriding without override))
$(P Virtual functions can currently override a function in a base class
without the 'override' attribute.
---
class A
{
void fun() {}
}
class B : A
{
// overrides but is not marked with override
void fun() {}
}
---
)
$(H4 Corrective Action)
$(P Mark overriding functions with $(D override)
---
class A
{
void fun() {}
}
class B : A
{
override void fun() {}
}
---
)
$(H4 Rationale)
$(P Making the $(D override) attribute mandatory makes it explicit, and can
catch errors when a base class function is accidentally overridden.
)
$(H3 $(DEPNAME Lower case 'l' suffix for integer literals))
$(P Lower case 'l' is an alternative suffix to denote 64 bit integer literals.
---
// deprecated code
// auto x = 123l;
---
)
$(H4 Corrective Action)
$(P Use the upper case 'L' suffix.
---
auto x = 123L;
---
)
$(H4 Rationale)
$(P The lower case suffix is easily confused with the digit '1'.
)
$(H4 Note)
$(P In lexical analysis phase, compiler can recognize lower case suffix 'l'
to report better error message - for the use case such as C-to-D code
translation. Thus DMD would continue to parse 'l' suffix.
)
$(H3 $(DEPNAME Variable shadowing inside functions))
$(P Variable shadowing is when a variable in an inner scope has the same
name as a variable in an enclosing scope.
---
void myFun()
{
int var;
if (x)
{
int var;
var = 3; // which var was meant?
}
}
---
)
$(H4 Corrective Action)
$(P Rename shadowing variables so they don't conflict.
)
$(H4 Rationale)
$(P Variable shadowing can introduce hard to find bugs where the wrong
variable is modified.
)
$(H3 $(DEPNAME Upper case 'I' suffix for imaginary literals))
$(P The 'I' suffix can be used to denote imaginary floating point values.
---
// deprecated code
// auto x = 1.234I;
---
)
$(H4 Corrective Action)
$(P Use the lower case 'i' suffix.
---
auto x = 1.234i;
---
)
$(H4 Rationale)
$(P The 'I' suffix is easily confused with the digit '1'.
)
$(H3 $(DEPNAME if (v; e)))
$(P This syntax can be used to declare a variable in an if statement condition.
---
if (v; calculateAndReturnPointer()) { ... }
---
)
$(H4 Corrective Action)
$(P Replace with an auto declaration.
---
if (auto v = calculateAndReturnPointer()) { ... }
---
)
$(H4 Rationale)
$(P The syntax is clearer with auto.
)
$(H3 $(DEPNAME Removing an item from an associative array with delete))
$(P delete can be used to remove an item from an associative array.
---
int[int] aa = [1 : 2];
delete aa[1];
assert(1 !in aa);
---
)
$(H4 Corrective Action)
$(P Use .remove instead.
---
int[int] aa = [1 : 2];
aa.remove(1);
assert(1 !in aa);
---
)
$(H4 Rationale)
$(P The delete syntax is confusing and conflicts with the normal delete syntax.
)
$(H3 $(DEPNAME .offset property))
$(P The .offset property can be used to get member offset information.
---
struct S { int a, b; }
static assert(S.b.offset == 4);
---
)
$(H4 Corrective Action)
$(P Use .offsetof instead
---
struct S { int a, b; }
static assert(S.b.offsetof == 4);
---
)
$(H4 Rationale)
$(P The .offset syntax has been superseded by .offsetof
)
$(H3 $(DEPNAME .size property))
$(P The .size property can be used to get type size information
---
struct S { int a, b; }
static assert(S.size == 8);
---
)
$(H4 Corrective Action)
$(P Use .sizeof instead
---
struct S { int a, b; }
static assert(S.sizeof == 8);
---
)
$(H4 Rationale)
$(P The .size syntax has been superseded by .sizeof
)
$(H3 $(DEPNAME .typeinfo property))
$(P The .typeinfo property can be used to get the associated TypeInfo class.
---
T.typeinfo
---
)
$(H4 Corrective Action)
$(P Use typeid() instead
---
typeid(T)
---
)
$(H4 Rationale)
$(P The .typeinfo syntax has been superseded by typeid()
)
)
Macros:
DEPLINK=$(RELATIVE_LINK2 $0, $0)
DEPLINK2=$(LINK2 $1.html#$2, $2)
DEPNAME=$(LNAME2 $0, $0)
TITLE=Deprecated Features
STDFILEREF = <a href="phobos/std_$1.html">$(D std.$1)</a>