www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How high level is D?

reply bmelo <bmelo protonmail.com> writes:
Hi people, I’m new to D and I am curious about how high level is 
D compared to another languages. I have a list of what languages 
to compare and I wanna know where you would classify D among them.
The languages are: C, C++, Objective-C, D, Go, Swift, Pascal, 


When I talk about low and high level language I’m referring to 
how much control the language gives to the hardware and what has 
more abstraction levels.
Nov 21 2018
next sibling parent reply NoMoreBugs <NoMoreBugs gmail.com> writes:
On Wednesday, 21 November 2018 at 09:56:16 UTC, bmelo wrote:
 Hi people, I’m new to D and I am curious about how high level 
 is D compared to another languages. I have a list of what 
 languages to compare and I wanna know where you would classify 
 D among them.
 The languages are: C, C++, Objective-C, D, Go, Swift, Pascal, 


 When I talk about low and high level language I’m referring to 
 how much control the language gives to the hardware and what 
 has more abstraction levels.
Well, at a high level, D does support the notion of a class. However, D does not treat a class as an isolated conceptual unit (a type). You can pretend a class is such a unit however, by isolating it within its own module. So to understand D, you need to first understand the purpose of the module - and I still have trouble with that, since I use classes as the highest form of abstraction. As for low level, which I don't do, the compiler is now written in D isn't it? Presumably, that involves some pretty low level stuff ;-) So compare with languages that can do these two things, I would say. I'm not sure that Cobol has a compiler written in Cobol??
Nov 21 2018
parent reply Meta <jared771 gmail.com> writes:
On Wednesday, 21 November 2018 at 10:27:11 UTC, NoMoreBugs wrote:
 Well, at a high level, D does support the notion of a class.

 However, D does not treat a class as an isolated conceptual 
 unit (a type).

 You can pretend a class is such a unit however, by isolating it 
 within its own module.
What? D certainly does "treat classes as types". Every class in D is its own type and supoorts the reguar methods of encapsulation as you would expect. The only difference is that in D, private class members and methods are module-public, meaning that anything else in the module can freely access them. That does not break encapsulation by any means, however.
Nov 21 2018
parent reply Neia Neutuladh <neia ikeran.org> writes:
On Wed, 21 Nov 2018 16:30:30 +0000, Meta wrote:
 On Wednesday, 21 November 2018 at 10:27:11 UTC, NoMoreBugs wrote:
 Well, at a high level, D does support the notion of a class.

 However, D does not treat a class as an isolated conceptual unit (a
 type).

 You can pretend a class is such a unit however, by isolating it within
 its own module.
What? D certainly does "treat classes as types". Every class in D is its own type and supoorts the reguar methods of encapsulation as you would expect. The only difference is that in D, private class members and methods are module-public, meaning that anything else in the module can freely access them. That does not break encapsulation by any means, however.
NoMoreBugs and their 4-5 other aliases are extremely annoyed at D's `private` being private-to-the-module, like a third of programming languages, instead of private-to-the-type, like a different third of programming languages. It's apparently far too much work to put a type in a different module from code that shouldn't be able to access its private members.
Nov 21 2018
parent reply NoMoreBugs <NoMoreBugs gmail.com> writes:
On Wednesday, 21 November 2018 at 16:48:29 UTC, Neia Neutuladh 
wrote:
 NoMoreBugs and their 4-5 other aliases are extremely annoyed at 
 D's `private` being private-to-the-module, like a third of 
 programming languages, instead of private-to-the-type, like a 
 different third of programming languages. It's apparently far 
 too much work to put a type in a different module from code 
 that shouldn't be able to access its private members.
Actually, I pointed this out for a reason. (1) - it's just plain fact (i.e. the private state of a class, within a module, is not really private at all) expect (the 3 most widely used languages). If (2) weren't also fact, I would not feel inclined to mention it. Your constant attacks on me for not liking D's leaking class abstraction is a reflection of *your attitude* towards me. But my statement is factually correct. Better to know that upfront than to discover it by mistake, as many seem to do - me included. Please let me enlighten newcomers so that they understand D, without being constantly attacking for doing so, by people like you. What is your motive for doing so anyway?
Nov 21 2018
next sibling parent reply Neia Neutuladh <neia ikeran.org> writes:
On Thu, 22 Nov 2018 00:14:40 +0000, NoMoreBugs wrote:
 Your constant attacks on me for not liking D's leaking class abstraction
 is a reflection of *your attitude* towards me.
The "attacks" are because of sock-puppetry surrounding your position, not because of your position.
Nov 21 2018
parent NoMoreBugs <NoMoreBugs gmail.com> writes:
On Thursday, 22 November 2018 at 01:27:33 UTC, Neia Neutuladh 
wrote:
 On Thu, 22 Nov 2018 00:14:40 +0000, NoMoreBugs wrote:
 Your constant attacks on me for not liking D's leaking class 
 abstraction is a reflection of *your attitude* towards me.
The "attacks" are because of sock-puppetry surrounding your position, not because of your position.
I should not be subjected to these constant unfounded accusations of sock-puppetry (which is a means of deception) every time someone expresses a view that is similar to a view that I've expressed. What this tells me, is that (certain) people on these forums simply don't like the view that is being expressed. That tactic is actually well known, and sadly, often successful (cause most people are too dumb to realize what's going on). It's called.. meat-puppetry - where a person or persons intentionally interject into a discussion they do not agree with, not to constructively represent their view, but to generate 'buzz' to sway opinion and ultimately close down the discussion (cause they don't like or don't agree with the discussion). And btw, your user-handle can be seen doing just that, every time this topic comes up.
Nov 21 2018
prev sibling next sibling parent reply Laurent =?UTF-8?B?VHLDqWd1aWVy?= <laurent.treguier.sink gmail.com> writes:
On Thursday, 22 November 2018 at 00:14:40 UTC, NoMoreBugs wrote:

 would expect (the 3 most widely used languages).

 If (2) weren't also fact, I would not feel inclined to mention 
 it.
You can leave Java out of this list though. The following Java code will compile and run: ------------------------------ public class Main { private int _mainMember = 0; public static class InnerData { private int _innerDataMember = 1; } public static class InnerAccess { public void accessMembers(Main main, InnerData innerData) { System.out.println("Outer member from inner: " + main._mainMember); System.out.println("Other class member from same level: " + innerData._innerDataMember); } } public static void main(String[] args) { Main main = new Main(); InnerData innerData = new InnerData(); InnerAccess innerAccess = new InnerAccess(); System.out.println("Inner member from outer: " + innerData._innerDataMember); innerAccess.accessMembers(main, innerData); } } ------------------------------ It goes unnoticed since Java forces you to have one top-level class per module, but Java treats `private` exactly like D: at the module level. Within that module, any class can access any member from any other class, no matter if ti's marked as `private`.
Nov 22 2018
next sibling parent reply Neia Neutuladh <neia ikeran.org> writes:
On Thu, 22 Nov 2018 08:13:13 +0000, Laurent Tréguier wrote:
 On Thursday, 22 November 2018 at 00:14:40 UTC, NoMoreBugs wrote:

 (the 3 most widely used languages).

 If (2) weren't also fact, I would not feel inclined to mention it.
You can leave Java out of this list though. The following Java code will compile and run:
I pointed that out ages ago (multiple times) and the person just ignored it.
 It goes unnoticed since Java forces you to have one top-level class per
 module, but Java treats `private` exactly like D: at the module level.
 Within that module, any class can access any member from any other
 class, no matter if ti's marked as `private`.
Java can have multiple top-level classes per source file, but only one can be public. You can't access private variables from a different top-level class in the same source file.
Nov 22 2018
parent Norm <norm.rowtree gmail.com> writes:
On Thursday, 22 November 2018 at 16:05:28 UTC, Neia Neutuladh 
wrote:
 On Thu, 22 Nov 2018 08:13:13 +0000, Laurent Tréguier wrote:
 On Thursday, 22 November 2018 at 00:14:40 UTC, NoMoreBugs 
 wrote:
 [...]
You can leave Java out of this list though. The following Java code will compile and run:
I pointed that out ages ago (multiple times) and the person just ignored it.
 It goes unnoticed since Java forces you to have one top-level 
 class per module, but Java treats `private` exactly like D: at 
 the module level. Within that module, any class can access any 
 member from any other class, no matter if ti's marked as 
 `private`.
Java can have multiple top-level classes per source file, but only one can be public. You can't access private variables from a different top-level class in the same source file.
It is just some young kid trolling, ignore them. bye, Norm
Nov 22 2018
prev sibling parent reply Paulo Pinto <pjmlp progtools.org> writes:
On Thursday, 22 November 2018 at 08:13:13 UTC, Laurent Tréguier 
wrote:
 On Thursday, 22 November 2018 at 00:14:40 UTC, NoMoreBugs wrote:

 would expect (the 3 most widely used languages).

 If (2) weren't also fact, I would not feel inclined to mention 
 it.
You can leave Java out of this list though. The following Java code will compile and run: ------------------------------ public class Main { private int _mainMember = 0; public static class InnerData { private int _innerDataMember = 1; } public static class InnerAccess { public void accessMembers(Main main, InnerData innerData) { System.out.println("Outer member from inner: " + main._mainMember); System.out.println("Other class member from same level: " + innerData._innerDataMember); } } public static void main(String[] args) { Main main = new Main(); InnerData innerData = new InnerData(); InnerAccess innerAccess = new InnerAccess(); System.out.println("Inner member from outer: " + innerData._innerDataMember); innerAccess.accessMembers(main, innerData); } } ------------------------------ It goes unnoticed since Java forces you to have one top-level class per module, but Java treats `private` exactly like D: at the module level. Within that module, any class can access any member from any other class, no matter if ti's marked as `private`.
Actually that is wrong, it is one PUBLIC class per module. public class Main { private int _mainMember = 0; public static void main(String[] args) { Main main = new Main(); InnerData innerData = new InnerData(); InnerAccess innerAccess = new InnerAccess(); System.out.println("Inner member from outer: " + innerData._innerDataMember); innerAccess.accessMembers(main, innerData); } } class InnerData { private int _innerDataMember = 1; } class InnerAccess { public void accessMembers(Main main, InnerData innerData) { System.out.println("Outer member from inner: " + main._mainMember); System.out.println("Other class member from same level: " + innerData._innerDataMember); } } Main.java:11: error: _innerDataMember has private access in InnerData System.out.println("Inner member from outer: " + innerData._innerDataMember); ^ Main.java:25: error: _mainMember has private access in Main System.out.println("Outer member from inner: " + main._mainMember); ^ Main.java:26: error: _innerDataMember has private access in InnerData System.out.println("Other class member from same level: " + innerData._innerDataMember);
Nov 22 2018
parent Laurent =?UTF-8?B?VHLDqWd1aWVy?= <laurent.treguier.sink gmail.com> writes:
On Friday, 23 November 2018 at 07:26:28 UTC, Paulo Pinto wrote:
 Actually that is wrong, it is one PUBLIC class per module.

 [...]

 Main.java:11: error: _innerDataMember has private access in 
 InnerData
          System.out.println("Inner member from outer: " + 
 innerData._innerDataMember);
 
  ^
 Main.java:25: error: _mainMember has private access in Main
              System.out.println("Outer member from inner: " + 
 main._mainMember);
 
   ^
 Main.java:26: error: _innerDataMember has private access in 
 InnerData
              System.out.println("Other class member from same 
 level: " + innerData._innerDataMember);
Yes, Neia pointed that out too. My bad, I never knew about this. It does make `private` slightly inconsistent instead, since it doesn't behave exactly the same depending on whether it's in a top-level class or not.
Nov 23 2018
prev sibling parent Kagamin <spam here.lot> writes:
On Thursday, 22 November 2018 at 00:14:40 UTC, NoMoreBugs wrote:
 (1) - it's just plain fact (i.e. the private state of a class, 
 within a module, is not really private at all)


 would expect (the 3 most widely used languages).
Encapsulation is usually used to provide interface to library consumers, it doesn't serve much purpose inside the library. AFAIK java has a restriction 1 class per file, which would work there's a use case when a class has a lazily initialized field that shouldn't be accessed directly, but through a property, but there's no way to do it because the class can access its private fields, traditional access attributes won't save you there.
Nov 22 2018
prev sibling next sibling parent reply Dukc <ajieskola gmail.com> writes:
On Wednesday, 21 November 2018 at 09:56:16 UTC, bmelo wrote:
 Hi people, I’m new to D and I am curious about how high level 
 is D compared to another languages. I have a list of what 
 languages to compare and I wanna know where you would classify 
 D among them.
 The languages are: C, C++, Objective-C, D, Go, Swift, Pascal, 


 When I talk about low and high level language I’m referring to 
 how much control the language gives to the hardware and what 
 has more abstraction levels.
In this regard, D is a lot like C++ in the regard that it can go both low-level and high-level. You can go as low as you can with C/C++/Forth: You can drop the type system, manage raw memory and even embed assembly into code. But D can also get high-level and abstract a lot. Of the languages you listed, I don't think any of them, with possible exception of Swift (which I don't know about, except that it's a new language), or Forth with some VERY advanced meta library, can match expressive power of D.
Nov 21 2018
parent reply bmelo <bmelo protonmail.com> writes:
On Wednesday, 21 November 2018 at 11:26:04 UTC, Dukc wrote:
 On Wednesday, 21 November 2018 at 09:56:16 UTC, bmelo wrote:
 Hi people, I’m new to D and I am curious about how high level 
 is D compared to another languages. I have a list of what 
 languages to compare and I wanna know where you would classify 
 D among them.
 The languages are: C, C++, Objective-C, D, Go, Swift, Pascal, 


 When I talk about low and high level language I’m referring to 
 how much control the language gives to the hardware and what 
 has more abstraction levels.
In this regard, D is a lot like C++ in the regard that it can go both low-level and high-level. You can go as low as you can with C/C++/Forth: You can drop the type system, manage raw memory and even embed assembly into code. But D can also get high-level and abstract a lot. Of the languages you listed, I don't think any of them, with possible exception of Swift (which I don't know about, except that it's a new language), or Forth with some VERY advanced meta library, can match expressive power of D.
But D gives more access to hardware than Go? I listened about D not going so weel to embedded and operating system programming like C and C++ because GC. Is D's GC more able to give you hardware control than Go's GC?
Nov 21 2018
next sibling parent bachmeier <no spam.net> writes:
On Wednesday, 21 November 2018 at 12:30:28 UTC, bmelo wrote:

 But D gives more access to hardware than Go? I listened about D 
 not going so weel to embedded and operating system programming 
 like C and C++ because GC. Is D's GC more able to give you 
 hardware control than Go's GC?
You only need the GC to access all of D's standard library. D also has things like -betterC: https://dlang.org/spec/betterc.html It's not difficult to get rid of the GC, you just don't have as nice a language if you do that.
Nov 21 2018
prev sibling next sibling parent Kagamin <spam here.lot> writes:
On Wednesday, 21 November 2018 at 12:30:28 UTC, bmelo wrote:
 But D gives more access to hardware than Go? I listened about D 
 not going so weel to embedded and operating system programming 
 like C and C++ because GC.
Here's embedded D: https://github.com/JinShil/stm32f42_discovery_demo#the-good
Nov 21 2018
prev sibling parent Dukc <ajieskola gmail.com> writes:
On Wednesday, 21 November 2018 at 12:30:28 UTC, bmelo wrote:
 But D gives more access to hardware than Go? I listened about D 
 not going so weel to embedded and operating system programming 
 like C and C++ because GC. Is D's GC more able to give you 
 hardware control than Go's GC?
More machine-contorl than Go? Easily. Go's GC cannot be dropped, or so I've been told. In D, you can program even if the GC hasn't been implemented for your platform at all. The whole C standard library and large parts of Phobos are still in use, and you can still manage memory by RAII (Resource-Acquisition-Is-Initialization) idiom or by reference counting. You are still miles ahead of using C, and not necessarily worse off than with C++ either. Many third-party D libraries won't work without GC, but you can still use all C libraries and some C++ libraries (Can somebody tell what are the changes of C++ interop working in practice? No personal experience) from D. But what you need to consider for embedded targets is that unlike C/C++, D excepts at least 32-bit architechture by design. If one wants to program devices smaller than that, something else is needed.
Nov 21 2018
prev sibling parent =?UTF-8?B?QXVyw6lsaWVu?= Plazzotta <cmoi gmail.com> writes:
On Wednesday, 21 November 2018 at 09:56:16 UTC, bmelo wrote:
 Hi people, I’m new to D and I am curious about how high level 
 is D compared to another languages. I have a list of what 
 languages to compare and I wanna know where you would classify 
 D among them.
 The languages are: C, C++, Objective-C, D, Go, Swift, Pascal, 


 When I talk about low and high level language I’m referring to 
 how much control the language gives to the hardware and what 
 has more abstraction levels.
Hello there, I'm not able to comment on the hypothesis illustrated due to lack of expertise but here is a picture suggested by c2lang.org. However, I can't find the exact source so I'm posting here the french article dealing about une new implementation of C (i.d. C2) who used the visual comparison of several but not all languages's abstraction levels: https://www.developpez.com/actu/185979/C2-un-langage-qui-se-presente-comme-une-evolution-de-C-plus-rapide-sans-fichiers-d-en-tete-avec-systeme-de-build-integre-et-d-autres-changements/ You can directly look at the picture if it's more convenient for you: https://www.developpez.com/public/images/news/C201.png Please notice it doesn't involve all programming languages you are looking for a comparison but I hope it helps you a bit. It was posted on 2018/02/01.
Nov 21 2018