Opinions requested on my blog post about primitive obsession.

D

Daniel Pitts

So, I just finished the first draft of an article on the benefits of
avoiding primitive obsession. I'd like some feedback on the article.
<shameless>Also, posting this message is a good way to promote my
blog.</shameless>
Any feedback is very welcome. Either using the comment system, or by
following up on this thread. Comment system is preferred (think of it
as a followup-to header).
<http://virtualinfinity.net/wordpress/program-design/2007/10/28/primitive-obsession/>

Thanks,
Daniel.

P.S. If anyone has an opinion, positive or negative, about my
"advertising" my blog-posts in this manor, feel free to let me know
here. I don't want to be classified as a spammer, and I feel that I
contribute enough to this community that the occasional unsolicited
message is appropriate. Let me know if you feel otherwise.
 
R

Roedy Green

P.S. If anyone has an opinion, positive or negative, about my
"advertising" my blog-posts in this manor, feel free to let me know
here. I don't want to be classified as a spammer, and I feel that I
contribute enough to this community that the occasional unsolicited
message is appropriate. Let me know if you feel otherwise.

the big advantage to your way, is you can modify your essay based on
the feedback. If you do it via posts, your errors sit there forever
to mislead others.

So I figure anything more that a couple of paragraphs should be posted
as html.
 
R

Roedy Green


I have been lobbying since the 1970s for units of measure as a built
in feature to create a friendly language for engineers.

If you have both British and ISO measure in the same program, SO many
errors happen because of invalid assumptions about measure. Even with
pure ISO, powers of 10 errors are easy to make.

With declared units of measure you can have:
1. dimensionality consistency checks.
2. automatic unit conversion.

Units of measure are NOT classes. They are compile time modifiers to
primitives. You could think of them as generics for primitives.

see http://mindprod.com/jgloss/unitsofmeasure.html
 
C

Chris ( Val )

I have been lobbying since the 1970s for units of measure as a built
in feature to create a friendly language for engineers.

I understand completely :)

Before I moved into the IT world, I spent many years in the
metal and engineering trades, converting between Metric and
Imperial units on a daily basis.
If you have both British and ISO measure in the same program, SO many
errors happen because of invalid assumptions about measure. Even with
pure ISO, powers of 10 errors are easy to make.
Indeed.

With declared units of measure you can have:
1. dimensionality consistency checks.
2. automatic unit conversion.

Units of measure are NOT classes. They are compile time modifiers to
primitives. You could think of them as generics for primitives.

I don't see why the couldn't be represented as classes.
Units can be viewed as an abstraction to measurement types.

I haven't used AutoCAD in a while, but I'm reasonably sure that they
worked with units in such a way - You just specify the unit type and
begin drawing.
 
H

Hunter Gratzner

I have been lobbying since the 1970s for units of measure as a built
in feature to create a friendly language for engineers.

And that's why people have developed frink. http://futureboy.homeip.net/frinkdocs/

It didn't take them 30 years of lobbying. Just some Java coding.
If you have both British and ISO measure in the same program,

ISO? Do you mean SI? ISO doesn't do units.
If you have SO many
errors happen because of invalid assumptions about measure. Even with
pure ISO, powers of 10 errors are easy to make.

With declared units of measure you can have:
1. dimensionality consistency checks.
2. automatic unit conversion.
From an interactive Frink session (first line after an empty line is
the input, followed by Frink's response):

Frink
Copyright 2000-2007 Alan Eliasen, (e-mail address removed)
http://futureboy.us/frinkdocs/
Enter calculations in the text field at bottom.
Use up/down arrows to repeat/modify previous calculations.

var m is mass = 10 pounds
45359237/10000000 (exactly 4.5359237) kg (mass)

m = 11 pounds
498951607/100000000 (exactly 4.98951607) kg (mass)

m = 11 meters
BasicContext: Cannot set symbol m, ContextFrame threw exception:
Constraint not met--value must have dimensions of mass

m = 1 kg
1 kg (mass)

m -> pound
100000000/45359237 (approx. 2.2046226218487757)

10 volt
10 m^2 s^-3 kg A^-1 (electric_potential)

20 amp
20 A (current)

10 volt * 20 amp
200 m^2 s^-3 kg (power)

10 volt * 20 amp -> watt
200

10 volt * 20 amp -> meter
Conformance error
Left side is: 200 m^2 s^-3 kg (power)
Right side is: 1 m (length)

var p is power = 10 volt * 20 amp
200 m^2 s^-3 kg (power)

p = 10 watt
10 m^2 s^-3 kg (power)
 
P

Piotr Kobzda

Roedy said:
I have been lobbying since the 1970s for units of measure as a built
in feature to create a friendly language for engineers.

The Measures and Units API (JSR-275) seems to be the answer to your efforts.

See introductory article:
<http://www.javaworld.com/javaworld/jw-10-2007/jw-10-jsr275.html>

As the article states, there is still no decision on inclusion of the
JSR-275 API in Java 7. Up to now, there is also no mention of
'javax.measure' package in official list of Java 7 packages
(http://download.java.net/jdk7/docs/api/). So, my guess is that we
should wait a bit longer for that... Hopefully, intermediately we may
use mentioned in the article the reference "draft" implementation from
the JScience project (http://jscience.org/).


piotr
 
R

Roedy Green

I don't see why the couldn't be represented as classes.
Units can be viewed as an abstraction to measurement types.

If you make them a something like generics for primitives, they have
zero run time extra overhead. This is important for
computation-intensive engineering programs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top