Re: Beginner ?. Why does D suggest to learn java

2014-10-18 Thread via Digitalmars-d-learn

On Saturday, 18 October 2014 at 02:00:42 UTC, RBfromME wrote:
but i don't find the basics any easier to  learn than D's.  The 
biggest issue i personal find in getting deeper into  a 
language is the docs and examples. The python examples, beyond 
the basics usually get write into OO so you find your self 
trying to figure out OO while trying to sift through the 
examples.  Makes it a little harder to get going and figure out 
the available libraries while trying to figure OO at the same 
time.


If you find D more fun, then use D, but OO is little more than 
representing aspects of real physical objects in the computer:


If you want to write a program about cars you could group 
properties such as weight, top-speed and build-year and call that 
Vehicle, then add number of wheels and motorsize and call it Car 
or some other properties and call it Boat. Add a function print() 
to display all the info to each class Vehicle, Car and Boat. Then 
you can create a list of vehicles that store different properties 
for different types of vehicles while being able to treat all 
cars and boats the same when printing them.


That's basically it. Nothing magic.

The most important aspect of learning how to program is what 
universities tend to call datastructures and algorithms.  The 
basics is probably just 2-4 weeks.


If you already know Python a little bit you could try to use 
educational resources for Python and translate it into D, e.g.:


http://interactivepython.org/courselib/static/pythonds/index.html

The nice thing about Python that it is very close to what is 
called pseudo code, basically a shorthand used when sketching a 
program.


Summing it up, I personally think the hardest part in learning 
to use a specific language is the docs and and examples because 
they all throw you write into OO and you spend more time trying 
to figure out OO instead of how to use the standard lib or 
third party lib to get a basic task done.


You don't need to learn more OO than I wrote above, and perhaps 
not even that. What you need to learn to be productive in any 
imperative language is:


1. What an aggregate (of values) is, they are often called 
record, struct or class and how to create them.


2. Arrays and the provided operations on them (can be in language 
or libraries)


3. How to create links between aggregates (called references or 
pointers)


Then pick up an online course or book on data structures and 
algorithms. Introductory books and courses teach roughly the same 
stuff, so pick anyone you like.


Understanding libraries and their documentation becomes much 
easier when you know the basic terminology about data structures 
and algorithms. One of the most entertaining and useful courses 
in computer science.


Re: Beginner ?. Why does D suggest to learn java

2014-10-18 Thread Mike James via Digitalmars-d-learn

On Friday, 17 October 2014 at 08:44:00 UTC, Paulo  Pinto wrote:
On Friday, 17 October 2014 at 01:05:37 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

I don't understand. If at least it were C but java? why not D 
itself?
C is *awful* as beginner's language. never ever let people 
start with

C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, 
really! i
believe that it must be featured on the front dlang.org page!) 
but java

has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller 
userbase. and
all that things with classes are reference types and structs 
are not,
empty array is not empty array but is empty array and so on 
D may be
confusing a little. it's good to have some CS background to 
understood

that things.

just my cent and cent.



Better, go with FreePascal http://www.freepascal.org/ and 
discover all that those features that many C advocates spread 
as being close to the machine and other C only features, aren't 
exclusive of it.


Alongside support for real modules, OO and genericity.

Then with a head clean of bad C influences, jump into D.


--
Paulo


Don't tell him that - he may discover Freepascal/Lazarus is the 
holy grail of GUI programming and may never try D...  ;-)


-=mike=-


gdc: Compile error with normalize from std.uni

2014-10-18 Thread slycelote via Digitalmars-d-learn

I'm using gdc on Ubuntu 14.04. Is this ubuntu packaging issue?


bash:~/tmp$ cat test2.d
import std.uni, std.stdio;

void main() {
  writeln(normalize(Hello));
}


bash:~/tmp$ gdc test2.d
/usr/include/d/4.8/std/uni.d:6301: error: undefined identifier
tuple
/usr/include/d/4.8/std/uni.d:6262: error: template instance
std.uni.seekStable!(cast(NormalizationForm)0, char) error
instantiating
/usr/include/d/4.8/std/uni.d:6087: note: instantiated from here:
splitNormalized!(cast(NormalizationForm)0, char)
test2.d:4: note: instantiated from here:
normalize!(cast(NormalizationForm)0, char)
/usr/include/d/4.8/std/uni.d:6271: error: undefined identifier
tuple
/usr/include/d/4.8/std/uni.d:6087: error: template instance
std.uni.splitNormalized!(cast(NormalizationForm)0, char) error
instantiating
test2.d:4: note: instantiated from here:
normalize!(cast(NormalizationForm)0, char)
test2.d:4: error: template instance
std.uni.normalize!(cast(NormalizationForm)0, char) error
instantiating
bash:~/tmp$ gdc --version
gdc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.


Re: Returning multiple arrays from function - struct or byref the only option?

2014-10-18 Thread Laeeth Isharc via Digitalmars-d-learn

Thanks for the thoughts Meta and Ali.

Laeeth.


On Wednesday, 15 October 2014 at 17:56:06 UTC, Ali Çehreli wrote:

On 10/15/2014 09:48 AM, Laeeth Isharc wrote:

 struct RetStruct
 {
  double[] a;
  double[] b;
 }

 RetStruct myfunction(double x)

That's my preference. Tuples would work as well but they have 
two minor issues for me:


- Unlike a struct, the members are anonymous. (Yes, tuples 
members can have names as well but not when returning or 
creating conveniently by 'return tuple(a, b)'.)


- Unlike Python, there is no automatic tuple expansion so one 
has to refer to the members as result[0] and result[1], which 
is less readable than struct members. (Yes, there is some 
support for tuple expansion e.g. in foreach but it has some 
issues with the automatic foreach loop counter.)


Summary: I return by struct. :)

Ali




Re: gdc: Compile error with normalize from std.uni

2014-10-18 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 10:01:51 +
slycelote via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 I'm using gdc on Ubuntu 14.04. Is this ubuntu packaging issue?
yes. current gdc works fine.


signature.asc
Description: PGP signature


Re: Returning multiple arrays from function - struct or byref the only option?

2014-10-18 Thread Meta via Digitalmars-d-learn

On Wednesday, 15 October 2014 at 17:56:06 UTC, Ali Çehreli wrote:
- Unlike a struct, the members are anonymous. (Yes, tuples 
members can have names as well but not when returning or 
creating conveniently by 'return tuple(a, b)'.)


This works, but I agree it is a bit obscure (you may want to add 
it to your book if it's not already there):


import std.typecons;

Tuple!(int[], left, int[], right) foo(int n, int m)
{
return typeof(return)(new int[](n), new int[](m));
}

void main()
{
auto res = foo(2, 3);
assert(res.left.length == 2);
assert(res.right.length == 3);
}


The problem is that D does not allow implicit conversions when 
returning results from a function. Tuple!(int[], int[]) is 
implicitly castable to Tuple!(int[], left, int[], right), but 
you cannot return the result of tuple(new int[](n), new int[](m)) 
from foo(), as they are technically still different types, which 
would require an implicit conversion. This is (IMO) a problem; 
it's extremely annoying when trying to use std.typecons.Algebraic.




Re: Recommended GUI library?

2014-10-18 Thread Jacob Carlborg via Digitalmars-d-learn

On 2014-10-17 18:34, K.K. wrote:

I'm looking for suggestions for a GUI library, to create a
somewhat light GUI that can also be created without too much
fuss, and support for Windows  Linux.


Have a look at DWT [1]. It's basically the only D GUI framework that 
doesn't have any dependencies except for system libraries.


[1] https://github.com/d-widget-toolkit/dwt

--
/Jacob Carlborg


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-18 Thread Lucas Burson via Digitalmars-d-learn
On Saturday, 18 October 2014 at 00:53:57 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Sat, 18 Oct 2014 00:32:09 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:




Wow, your changes made it much simpler. Thank you for the 
suggestions and expertise ketmar :)


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-18 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 16:56:09 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 Wow, your changes made it much simpler. Thank you for the 
 suggestions and expertise ketmar :)
you're welcome.


signature.asc
Description: PGP signature


Re: Recommended GUI library?

2014-10-18 Thread K.K. via Digitalmars-d-learn

Thanks for the extra suggestions! I'll check them out.


[OT] the uses of computing

2014-10-18 Thread Joakim via Digitalmars-d-learn
On Saturday, 18 October 2014 at 00:06:10 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 23:31:45 +
Joakim via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

You do realize that most people are clueless about how to fix 
those also, right?

most people are stupid.


No disagreement there, but even the smart ones can only learn so 
much.


Would you require that how to fix all that mechanical stuff be 
taught in schools too?
but it is! or at least it was. it's all simple physics, you 
know. not a

rocket science.


Many people do not learn simple physics in school, and even if 
they did, wouldn't necessarily be able to figure out how to fix a 
specific mechanical system like a washing machine from the 
general physical principles.


Kids would never leave school if they had to learn all the 
stuff everybody says they should be forced to learn. ;)
nobody should be *forced* to learn: it's pointless. yet kids 
are very
curious, and they can be taught *alot* of things if they think 
that
they are just playing. make it interesting, and you'll be 
amazed how

much kids can learn almost without problems.


Yeah, we agree if you truly mean making most of what they learn 
optional, not just fun but still required.  Most of the stuff 
we force on kids today, like multiplication tables, how to divide 
numbers by hand, or memorizing historical dates, is utterly 
useless.


Yet, civilization is made up of people like you, who would all 
miss those mechanical systems far more than computers.
it's a huge difference between i miss my washing machine and 
all our

communication and data processing systems are foobared.


Yet, I bet you they'll want that washing machine working far more 
than the internet.


They should use tools like Automator instead, no programming 
needed:


http://en.wikipedia.org/wiki/Automator_(software)
i wasn't talking about sorting out file mess. i was talking 
about
tabular data processing, for example, with some logics and 
calculations

that can't be done automatically without programming.


Isn't that what people use Excel macros for?  There are 
specialized tools for the job, that are more limited than full 
programming languages but easier to use for the average person.



Tablets are optimized for basic usage
what is basic usage? i really don't know what tablets are 
for. what i
can do with it? watching movie? listening music? reading book? 
yes,

tablets can do this... badly. what else?


All of the above, anything you'd use a portable computer for that 
doesn't require much typing and would benefit from a larger 
screen than your smartphone.  I wouldn't say they do it all 
badly: it's the most portable TV you could ever have, if you 
use it to watch video.  And you're not limited to the junk on the 
idiot box, you can download any video from the web and watch on 
the go.  Most websites benefit from a larger screen also.



i can listen music with my N900, and it fits in my pocket.

movies? on tablet screen? no, thanks.

books? electronic books are better.


I've watched parts of movies on my 4.7 smartphone screen, which 
happens to have the best display I've ever used.  Tablets are 
even better for video.  I don't read books anymore, but with 
their high-res displays up to 200-300 ppi these days, reading 
text is very nice on tablets too.



tablets are like XML: bad for everything.


Now that's just low, you can't compare anything to the utter junk 
that is XML. :)


Most people just need a basic appliance that isn't going to 
catch viruses or require registry hacks.

give 'em wooden board with painting. it's great!


It's a little better than that. ;)

It is completely different, because there are tools like 
Automator to help you automate your workflow without needing 
to write anything.

oh, please. i can do batch renaming with wildcards, and for any
task that is more complex than that there *is* a need to write
logic. scripts. graphic programming is a dead end. people 
drop icons

in favor of alphabet 'cause alphabet is just better.


Actually, the progression went the other way, people dropped text 
UIs for graphical UIs. :) I'm not saying _you_ need to leave the 
terminal, but for most people GUI tools like Automator are enough.


If you need to communicate something on paper- well, nobody 
uses paper these days
i wish that the goverment of my country knows about that. and 
banking.

somehow they still insist to have everything written on paper.


Well, the government is the most backwards part of any country.

For most people, that is a better route, particularly if they 
don't need to modify the script as they go and just need it 
written once.
so instead of spending ten minutes to write the script they'll 
spend a
day searching for someone to hire and pay him money. great. 
thanks to

such people we have don't put your pet into microwave-like
instructions. and that instructions are pointless 'cause such 
people

never reads any instructions 

Re: Any dub tips and tricks

2014-10-18 Thread Joel via Digitalmars-d-learn

There is a mistake in the dil package.json
excludedSourceFiles should be an array of strings, not just a 
string.


But I don't get those errors on my OSX.


Re: [OT] the uses of computing

2014-10-18 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 19:42:50 +
Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

  most people are stupid.
 No disagreement there, but even the smart ones can only learn so 
 much.
that's why we should teach kids alot of things while their minds are
clear and ready to absorb alot of knowledge. and, of course, we must
teach them how to *use* that knowledge.

 Many people do not learn simple physics in school, and even if 
 they did, wouldn't necessarily be able to figure out how to fix a 
 specific mechanical system like a washing machine from the 
 general physical principles.
yes, figuring this out without manuals will be hard. but learning
physics (proper learning of *anything* for that matter) will give 'em
understanding of base principles (mechanics, electricity, etc) and the
ability to extract information from books. it's enough for simple fixes
that doesn't require to produce hi-tech parts.

 Yeah, we agree if you truly mean making most of what they learn 
 optional, not just fun but still required.  Most of the stuff 
 we force on kids today, like multiplication tables, how to divide 
 numbers by hand, or memorizing historical dates, is utterly 
 useless.
ah, i hated that so-called history lessons where i was forced to
remebmer that in year i don't care about somebody who i don't care
about did something i equally don't care about. ;-)

yes, i'm sure that we should teach kids how to do things, not just
making 'em remember that 4*8 is 32. tell 'em what multiplication is and
then play games with them, games which involves using of
multiplication. this way kids will learn how to use multiplication. no
need to remember any tables.

or let 'em build a simple robot and program it to do some funny things.
it's exciting and they will learn many things about mechanics,
electricity, programming...

let 'em play a role of factory manager, for example, and they will
develop a good understanding of how economics works.

and so on.

  Yet, civilization is made up of people like you, who would all 
  miss those mechanical systems far more than computers.
  it's a huge difference between i miss my washing machine and 
  all our
  communication and data processing systems are foobared.
 Yet, I bet you they'll want that washing machine working far more 
 than the internet.
most people can't see a whole picture. it's bad. we must teach kids to
understand how different things are interconnected too.

 Isn't that what people use Excel macros for?
aren't writing excel macros a programming?

 There are 
 specialized tools for the job, that are more limited than full 
 programming languages but easier to use for the average person.
i never meant that all people should learn full programming
languages. they have to know how to write algorithms, but not
necessary what pointer is or what is the difference between manual
memory management and garbage collecting. yet if i'll show 'em simple
recursive fibonacci function, they must be able to understand it. hey,
it's lambda calculus, and lambda calculus is so simple, that even
7-year kid can understand it! i checked that, kids are really able to
understand it. ;-)

 All of the above, anything you'd use a portable computer for that 
 doesn't require much typing and would benefit from a larger 
 screen than your smartphone.
instagram and social networks. ;-) two of the most useless things on
the planet.

 And you're not limited to the junk on the 
 idiot box, you can download any video from the web and watch on 
 the go.
and can't easily mark and categorize that until someone wrote
web-service for it. 'cause for doing it locally i need... ah, to
write some scripts. and i have no keyboard (no, that on-screen crap may
be good for tweeting, but it's generally unusable). i.e. tablets *are*
idiot boxes, just with fancy pictures from over the world.

 I don't read books anymore
even technical ones? ;-)

 but with 
 their high-res displays up to 200-300 ppi these days, reading 
 text is very nice on tablets too.
i prefer to use some specialised device to reading text. it's smaller,
it was made especially for reading texts and it can last alot longer
without recharging.

i mean that tablets can do all that things, but specialised devices are
just better. and if i know that i'll have to spend some time waithing
for something, i'll take my player and ebook with me. or subnotebook
-- hey, it has real keyboard!

  tablets are like XML: bad for everything.
 Now that's just low, you can't compare anything to the utter junk 
 that is XML. :)
ah, you are right. tablets sometimes can be useful. ;-)

 Actually, the progression went the other way, people dropped text 
 UIs for graphical UIs. :)
that's 'cause they never used good UIs and we have no truly component
environments. Oberon system was great even with it's TUI, and it was
really exciting with it's gadgets UI. i'm still missing my Oberon
system.

by the way, if D will develop good runtime reflection (which is

Re: [OT] the uses of computing

2014-10-18 Thread Joakim via Digitalmars-d-learn
On Saturday, 18 October 2014 at 20:50:42 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Sat, 18 Oct 2014 19:42:50 +
Joakim via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


 most people are stupid.
No disagreement there, but even the smart ones can only learn 
so much.
that's why we should teach kids alot of things while their 
minds are
clear and ready to absorb alot of knowledge. and, of course, 
we must

teach them how to *use* that knowledge.


So much of what's taught today is so worthless that I'm skeptical 
of anyone claiming kids should be taught a lot, as if you know 
what that is.  And given our long history of barely being able to 
teach any knowledge, with almost no success in getting people to 
use it for something original, that seems like a dead end too.  
Better to just let people take their own path and find what works 
best for them.


Many people do not learn simple physics in school, and even if 
they did, wouldn't necessarily be able to figure out how to 
fix a specific mechanical system like a washing machine from 
the general physical principles.
yes, figuring this out without manuals will be hard. but 
learning
physics (proper learning of *anything* for that matter) will 
give 'em
understanding of base principles (mechanics, electricity, etc) 
and the
ability to extract information from books. it's enough for 
simple fixes

that doesn't require to produce hi-tech parts.


I disagree, as there is a large gap of knowledge between the base 
principles and the complex systems we build on top.  How many 
people would be able to diagnose and force reallocation of bad 
sectors in their hard disk if hit with that problem, given the 
basics of how hard disks work?  I actually ran into this recently 
and found little info about it, meaning not many people do it.


Yeah, we agree if you truly mean making most of what they 
learn optional, not just fun but still required.  Most of 
the stuff we force on kids today, like multiplication tables, 
how to divide numbers by hand, or memorizing historical dates, 
is utterly useless.
ah, i hated that so-called history lessons where i was forced 
to
remebmer that in year i don't care about somebody who i don't 
care

about did something i equally don't care about. ;-)

yes, i'm sure that we should teach kids how to do things, not 
just
making 'em remember that 4*8 is 32. tell 'em what 
multiplication is and

then play games with them, games which involves using of
multiplication. this way kids will learn how to use 
multiplication. no

need to remember any tables.

or let 'em build a simple robot and program it to do some funny 
things.

it's exciting and they will learn many things about mechanics,
electricity, programming...

let 'em play a role of factory manager, for example, and they 
will

develop a good understanding of how economics works.

and so on.


We agree that practical application is a better way to motivate 
learning than absorbing theory from a book first, at least for 
most students.  But some kids are just not going to enjoy those 
multiplication games or robot building and I'd say it's better 
for them to choose something else to pursue, rather than forcing 
them to pick up multiplication when it's a completely useless 
skill, now that everybody carries around a calculator with them 
in their phone these days.


 Yet, civilization is made up of people like you, who would 
 all miss those mechanical systems far more than computers.
 it's a huge difference between i miss my washing machine 
 and all our

 communication and data processing systems are foobared.
Yet, I bet you they'll want that washing machine working far 
more than the internet.
most people can't see a whole picture. it's bad. we must teach 
kids to

understand how different things are interconnected too.


At this point, _I_ can't see your whole picture. :) I made a 
simple point, that building and fixing washing machines or 
software is something most people don't want to do.  Saying they 
should learn those things anyway doesn't make sense.



Isn't that what people use Excel macros for?

aren't writing excel macros a programming?


My understanding is that you can write simple mathematical 
formulas, which is as far as most probably go, even though it may 
also allow iteration and other programming constructs.  My point, 
that I made below, is that people who need some of the power of 
programming without the training can use cruder tools like these 
most of the time.


There are specialized tools for the job, that are more limited 
than full programming languages but easier to use for the 
average person.

i never meant that all people should learn full programming
languages. they have to know how to write algorithms, but not
necessary what pointer is or what is the difference between 
manual
memory management and garbage collecting. yet if i'll show 'em 
simple
recursive fibonacci function, they must be able to understand 
it. hey,
it's 

Assignment to enumerated string, is content copied or array information?

2014-10-18 Thread tcak via Digitalmars-d-learn

enum Values: string{
  NONE = ,
  Value1 = Apple,
  Value2 = Peach,
  Value3 = Lemon
}


Values lastHeldValue = Value3;


Is the lastHeldValue just pointer + length information, and it
points to Lemon; or is Lemon copied to another place in 
memory?


I am doing comparison as if( lastHeldValue == Value3 ) and am 
not

sure what comparison operation it is doing in the background.


DDoc module description?

2014-10-18 Thread Jeremy DeHaan via Digitalmars-d-learn
Although perhaps unnecessary, I added DDoc documentation to my 
module for a short description of the body. This showed up in the 
place I wanted it to be in when I built the html documentation, 
so I was pretty happy. (below the module name and before any 
module members)


I then went to override the DDOC macro to set it up with the 
correct formatting with the rest of the site I'll be putting the 
documentation on. The single line documentation I had written for 
the module apparently does not reside in BODY, and with the new 
formatting, it just casts it to the bottom of the page. It now 
resides below the footer.


Is there anything I can do to correct this? If not then I'll just 
say screw it and not bother, but I thought it looked pretty 
nice. Especially for modules that have more than one class in 
them.


Re: Assignment to enumerated string, is content copied or array information?

2014-10-18 Thread Meta via Digitalmars-d-learn

On Saturday, 18 October 2014 at 23:51:53 UTC, tcak wrote:

enum Values: string{
  NONE = ,
  Value1 = Apple,
  Value2 = Peach,
  Value3 = Lemon
}


Values lastHeldValue = Value3;


Is the lastHeldValue just pointer + length information, and 
it
points to Lemon; or is Lemon copied to another place in 
memory?


I am doing comparison as if( lastHeldValue == Value3 ) and am 
not

sure what comparison operation it is doing in the background.


The value will be copied and pasted where you use a Values. 
However, strings are cached in D, so the following problem will 
print true for both checks.


import std.stdio;

void main()
{
enum s = test;
auto v1 = s;
auto v2 = s;

//Check that both point to the same string in memory
writeln(v1 is v2);

//Check that both have the same value
writeln(v1 == v2);
}

Because enum values are copied and pasted, it is usually a bad 
idea to make an enum that contains arrays or classes, as 
everywhere you use the enum values allocates a new array/object. 
With strings it's okay, as they're cached.


How to convert from ubyte[] to and from float?

2014-10-18 Thread Charles Hixson via Digitalmars-d-learn

What is the best way to convert from a part of a ubyte[] to a float?

I've tried converting the ubyte[] into a uint, but neither casting the 
uint to a float nor to!float work.


I suppose I could use a trick record union, but that seems inelegant.  
If I use pointers, the alignment may (unpredictably) not be proper 
(whatever that means these days).


Re: [OT] the uses of computing

2014-10-18 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 23:38:35 +
Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

don't you think that we are going in circles now? not that i'm tired of
this conversation, but i see that we get each other's POVs, and have no
more arguments to convince each other. ;-)

i respect your opinions but just don't agree with them. ;-)
besides, it's increasingly hard for me to answer, 'cause my English
writing skill is awful. i can understand you but can't clearly express
myself.


  I don't read books anymore
  even technical ones? ;-)
 I think the only technical book I've read in the last decade is 
 Andrei's TDPL, which I bought in print and got about halfway 
 through.  I've probably read bits and pieces of maybe five other 
 non-technical books here and there in the same timespan, which 
 were all given to me as gifts.  I've never read an ebook, yet I 
 read extensively online.  Books are an outdated form, now that we 
 have blogs.
i believe that blog posts and textbooks compliments each other. i
prefer textbook for learning new language, for example, and read blogs
to learn some interesting/funny/hidden features.

 I don't know much about Oberon, but that gadgets UI sounds like 
 it's still a GUI.
sure, it's GUI, but with some consolish pieces dropped in. you can
connect components and you can write some textual commands/scripts to
modify component behavior. best from both worlds! ;-)

 I actually agree with you that some sort of component system like 
 that is likely the future, even if it's only ultimately used to 
 make developers' lives easier and largely unconfigured by users 
 themselves
it's simple enough for users to modify. changing layouts by dragging
components, embedding components into components and so on. this things
are mostly visual and easy.

people love to customize their working environment if it's easy
enough. ;-)

 though I haven't looked much into the complex 
 historical reasons why it hasn't happened yet.
'cause so-called software industry is not ready to die yet. ;-) with
proper component system there will be no much sense in selling
applications. and selling components is much harder: how many people
will buy e-mail data source component? it's not even visual!

and selling e-mail reader is worthless, 'cause people will
deconstruct it to basic parts and build their own application, and
will not buy shiny new version with improved interface. they will not
even buy the full package if they only need one part of it, like
faster e-mail data source component.

so the only way to keep software bussines (as we know it) running is
turning component system back to non-component one. take, for example,
COM technology (which is badly done, but still usable component
system). how much software uses COM to decouple application in reusable
parts? even microsoft realised that this will be disaster and turned
COM to advancing scripting interface instead of truly component
system.

  have you ever seen BlackBox Component Builder? it's written in
  Component Pascal, but the basic principles are 
  language-independent.
  i'm dreaming about BCB with D as base language...
 No, never heard of it, sounds interesting.
try it, it's fun and free! ;-) you'll see component programming
system in action. it's not component OS, but it's great programming
environment nevertheless. D is almost capable of powering such system.

if only i had more free time and motivation... creating something
BCB-like can be that killer app D needs.


signature.asc
Description: PGP signature


Re: How to convert from ubyte[] to and from float?

2014-10-18 Thread Ali Çehreli via Digitalmars-d-learn

On 10/18/2014 06:06 PM, Charles Hixson via Digitalmars-d-learn wrote:

What is the best way to convert from a part of a ubyte[] to a float?

I've tried converting the ubyte[] into a uint, but neither casting the
uint to a float nor to!float work.

I suppose I could use a trick record union, but that seems inelegant.
If I use pointers, the alignment may (unpredictably) not be proper
(whatever that means these days).


This is what I understood:

import std.exception;

ubyte[float.sizeof] toBytes(float f)
{
ubyte* beg = cast(ubyte*)f;
return beg[0..f.sizeof];
}

float toFloat(const(ubyte)[] bytes)
{
enforce(bytes.length = float.sizeof);
return *cast(float*)bytes.ptr;
}

void main()
{
float f = 1.5;

auto bytes = toBytes(f);
float f2 = toFloat(bytes);

assert(f2 == f);
}

There are no alignment issues because f and ubyte[float.sizeof] are not 
related. If you meant that ubyte[] should be a reference to an existing 
float, then toBytes must take by 'ref float' and then it can return a 
ubyte[]. However, it would be the responsibility of the caller to ensure 
that the float would live long enough.


If that happened, then there would be no alignment issues because we 
would have started with a float anyway and the ubyte[] would be 
referring to that float in memory.


Ali