Are units of measurement unique to F#? [closed] - programming-languages

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I was reading Andrew Kennedy's blog post series on units of measurement in F# and it makes a lot of sense in a lot of cases. Are there any other languages that have such a system?
Edit: To be more clear, I mean the flexible units of measurement system where you can define your own arbitrarily.

Does TI-89 BASIC count? Enter 54_kg * (_c^2) and it will give you an answer in joules.
Other than that, I can't recall any languages that have it built in, but any language with decent OO should make it simple to roll your own. Which means someone else probably already did.
Google confirms. For example, here's one in Python. __repr__ could easily be amended to also select the most appropriate derived unit, etc.
CPAN has several modules for Perl: Physics::Unit, Data::Dimensions, Class::Measure, Math::Units::PhysicalValue, and a handful of others that will convert but don't really combine values with units.

Nemerle had compiler-checked Units of Measure in 2006.
http://nemerle.org
http://nemerle.org/forum.old/viewtopic.php?t=265&view=previous&sid=00f48f33fafd3d49cc6a92350b77d554

C++ has it, in the form of boost::units.

I'm not sure if this really counts, but the RPL system on my HP-48 calculator does have similar features. I can write 40_gal 5_l + and get the right answer of 156.416 liters.

I believe I saw that Fortress support this, I'll see if I can find a link.
I can't find a specific link, but the language specification makes mention of it in a couple of places. The 1.0 language specification also says that dimensions and units were temporarily dropped from the specification (along with a whole heap of other features) to match up with the current implementation. It's a work in progress, so I guess things are in flux.

F# is the first mainstream language to support this feature.

There is also a Java specification for units at http://jcp.org/en/jsr/detail?id=275 and you can already use it from here http://jscience.org/

Nemerle has something much better than F# !
You should check this one : http://rsdn.ru/forum/src/1823225.flat.aspx#1823225 .
It is really great .
And you can download here : http://rsdn.ru/File/27948/Oyster.Units.0.06.zip
Some example:
def m3 = 1 g;
def m4 = Si.Mass(m1);
WriteLine($"Mass in SI: $m4, in CGS: $m3");
def x1 = Si.Area(1 cm * 10 m);
WriteLine($"Area of 1 cm * 10 m = $x1 m");

I'm pretty sure Ada has it.

well I made QuantitySystem library especially for units in C#, however its not compile time checking
but I've tried to make it run as I wanted
also it supports expansion so you can define your unique units
http://QuantitySystem.CodePlex.com
also it can differentiate between Torque and Work :) [This was important for me]
the library approach is from Dimension to units
all I've seen till now units only approach.

I'm sure you'd be able to do this with most dynamic languages (javascript, python, ruby) by carefully monkey-patching some of the base-classes. You might get into problems though when working with imperial measurements.

Related

How to effectively organize code in languages where the implementation and interface declaration are typically in the same file [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I usally code in C and C++ where implementation and declaration are in different files (.c/.h and .cpp/.hpp), but I often code in Haskell/Python/D where this distinction does not exist.
My problem is when my code tends to grow I struggle to have a clear vision of what is inside a file. I miss the "you know what to expect just by looking at the .h" and tend to become overwhelmed by the feeling of mess.
My best attempt to solve this is to put fold into the file, but I would like to know how do you do guys? Do you have some magic solutions that I haven't tried yet? Is that just a set of mind?
I continue to use separate files like you do in C++ and like Java enforces in other languages, and make a lot of use of import/require/etc. Just because it is not enforced by the language does not mean you can't systematically organize your file name and content ^_^
I don't think there are magic solutions, but the following tips might work
Use classes
Describe for each class their resonsibility
Write down which data is used in each class
Write down which functionality is used in each class
Start with small classes, they will grow eventually
When classes getting too big, split them.
Use one file per class.
Split methods/data in public/private (with the use of the convention _)
for Java, the maven structure helps a bit.
src/main/java
for your Main code
and
src/test/java
for your Test code.
Also in addition to that I follow this package structure.
All the interfaces which form the core api will be in a package ending with api.
The implementations will be in a package ending with impl.
I use the Java convention of placing classes and interfaces of a given name in a file with that name as much as possible. I also use Maven which has a default directory structure which is a pain to start with but very useful if you have to look at other people projects.
Do you have some magic solutions that I haven't tryed yet
I suggest the simpler the better. Less to remember. ;)

Learning a new language project [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does anyone have a standard project that they use when learning a new language. Kinda like a specification document of a project that includes all aspects of programming. Does anyone use some sort of beginning type project when learning a new language? I guess it also depends on the type of language and what's it's capable of.
Contributing something to an open source project seems to work for me. In addition to getting exposed to some coding habits in the language , you get to work on something useful.
Going through the first few problems of Project Euler is a very good way to get a handle on topics like I/O, recursion, iteration, and basic data structures. I'd highly recommend it.
A friend of mine had a coworker who coded a minesweeper every time when he wanted to learn a new language with GUI.
I like making simple websites for learning.
Pro: you can put it online and show it to people.
Con: the language has to be suitable for web development.
Writing a simple ray tracer:
math functions (pow, sqrt, your own intersection routines)
recursion (because it is a whitted style recursive one)
iteration (for all pixels)
how to write custom types (rays, possibly vectors)
pixel wise graphics
have something to play with compiler's (optimization-) flags
optional:
simple GUI
file reading writing
I've also done so with metatrace.

Choosing a Job based on languages? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
How often is language the deciding factor for selecting a job?
Many of us here are well versed in many languages, C++, Java, C#, and likely have many other languages under our belt for the right occassion (really any occasion is the right occasion for Python, AMIRITE?), so this isn't so much a question of choosing a job that is a good fit based on your skill set. Rather, if you are skilled with most languages, do you pick your favorite, or do you follow the money (given the tight economy).
I'm considering coming out of retirement, and have started to look around and what's available.
Over the years, I've moved towards C# and Python; many jobs in the area are looking for .NET developers, but there are plenty of them that do not. I cut my teef on C++, consider myself adept at the language, and know my way around a Java. But I find myself really digging what they're doing to C#, and I have always loved python.
Even if the work will be interesting, how important is the language to you?
I think that although in its essence programming is bigger than any language(languages are just the means, not the goals) everyone has a preference toward some languages. However, it often turns out that our preferences are towards languages not considered mainstream.
I live and work in Bulgaria(a country known from the movies as the center of crime in Europe, though that's not the case). Here 90% of the job ads are for PHP, Java and C# developers... There is also C for embedded development(which I hate), C++ (for maintenance of older systems - no one starts new projects in C++ anymore) and Cobol :-) I'd very much like to make money developing in Clojure or Ruby for instance, but the reality is that there is simply no demand around here. Of the three options I've found Java to appeal most to me - it's a nice language, with a nice community around it and a great VM behind it. So I naturally consider Java ads first, but I'm always open to any challenges as long as find them intriguing...
I would think that one would have a bias towards not just the language they want to develop in, but in the environment and type of applications they are likely to be working with. I think that would be the deciding factor?
Java - Coffee grinder
Python - Snake charmer
C - Optician
C# - Laser eye surgeon
C++ - Night vision goggle manufacturer
Ruby - Jeweller
.NET - Fisherman
the language itself doesnot matter so much, as the technology used does.
for example, a php/mySQL developer could easier convert to ASP.NET/MSSQL, than a .NET Windows Forms programmer will. I was both and felt more support from my php/mysql skills than my desktop C# programming ones.
But when the working process is annoying to you (e.g. you don't even want to go back to C++ coz it was hell for you), you better go find .NET desktop jobs - you will find that 90% of work done in the past by you in C++ was abstracted in .NET libraries and you'll get more fun from programming (though some people love that so-called 'c++ hell' for hacking).
as Chuck Jazdzewski fatherly said, (at the end of http://www.removingalldoubt.com/PermaLink.aspx/a32977e2-cb7d-42ea-9d25-5e539423affd ) , programming is fun, but shipping is your job. Joel Spolsky (www.joelonsoftware.com) has also nice entries about that.
Consider this when you are looking for a new working environment.
I've chosen Java. I know many more, but I think its the best decision to stick with one. If you work one year Java, one year c#, one year python you will not get a job as Java programmer that should have at least 3 years of experience.
For a coder, who's profession is based on it, is should be the main deciding factor. (...with Money a very close second!)
This may sound shallow but I tend to stick with the one I know best. Having spent several years in C# and .NET I wouldn't go back to PHP or Java, not because they are bad but rather I don't want to have to re-learn everything again... it would be sort of like starting all over again.

Languages that free you from clarifying your ideas [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
ok, so is there a programming language that frees you from clarifying your ideas?
I couldn't help asking. But if there is one, what would you say comes closest today?
You mean, a programming language that lets you program without explaining what you want the program to do?
No, how would that work? The compiler needs to be told what program to compile.
Digging out an old, somewhat appropriate quote from Charles Babbage:
On two occasions I have been asked,
'Pray, Mr. Babbage, if you put into
the machine wrong figures, will the
right answers come out?' I am not able
rightly to apprehend the kind of
confusion of ideas that could provoke
such a question.
The compiler can't read your mind. The only way it can create a program to do what you want is to tell it what it is you want.
Of course, there are languages that free you from having to specify things that are irrelevant to your overall problem and are only relevant to the underlying implementation. (an obvious example is that most modern languages free you from having to worry about pointers or many other low-level concerns. Many languages also give you ways to iterate over sequences without having to write a manual for-loop. But you still have to "clarify your ideas", you still have to specify what your program should do. The best a language can do is free you from clarifying the things that are not relevant to your ideas.
That shouldn't be the role of a language, in my view. Instead, the language should help you to clarify your ideas, and let you express those clarified ideas in as intuitive a way as possible.
You could see it from two angles:
High-level languages like Prolog
free you from having to express every
messy detail of your algorithm. You just
sketch the high-level picture, and
prolog fills in the details (e.g.,
how to do search and deduct the
answers to your questions, etc).
On the other side of the spectrum,
low-level languages like C free you
from having to express your ideas in
an abstract way. You can just give a
sequence of very concrete, detailed
procedural steps (although you can
optionally introduce abstractions if
you want to).
So both extremes free you from certain aspects of expressing and clarifying your ideas.
I don't think so, but there are a few that prevent you from clearly expressing those ideas - I nominate BCPL.
For various problem domains, there are languages that free you from having to type a lot of stuff beyond what's necessary to clarify your ideas. But every language fails in some situations, and for some people. Not everybody is comfortable expressing their ideas in an object oriented design (say, C# or Java), as functions and closures (Scheme), as logical derivations (Prolog -- there are some problems for which it fits!), or as declarative statements of the desired result (XSLT, CSS, various DSL's, with varying success) -- yet each of these is the right answer in certain contexts, and most of them overlap to some extent. Indeed, few modern languages are all that purely oriented to single paradigms.
But some languages favour other things over expressiveness: such as having efficient implementations (C), or being easy to learn (say, Python or its scripting kindred).
I hope there isn't a language that frees you from clarifying your ideas. It should be the responsibility of all programmers to do that themselves, not to pass it off to some other person or programming construct.
All good points, was thinking more along the lines of scripting languages, where you can type away in the debugger until it does what you want (I've done that a time or two for some sysadmin wmi scripts).
Yes, Whitespace.

Under what circumstances are dynamic languages not appropriate? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What factors indicate that a project's solution should not be coded in a dynamic language?
Familiarity and willingness of the programmers to work with the language.
Your dynamic language is probably my static language.
System level development is a key group of software that typically shouldn't be in dynamic languages. (drivers, kernel level stuff, etc).
Basically anything that needs to have every ounce of performance or low level hardware access, should be in a lower level language.
Another indicator is if it is highly number crunching, like scientific data number crunching. That is, if it needs to run fast and do number crunching.
I think a common theme is processor intensive problems... in which case you will easily see the performance differences, and you will find that the dynamic language just can't give you the power to use the hardware effectively.
That said, if you are doing processor intensive work and you don't mind the hit in performance, then you could still potentially use a dynamic language.
Update:
Note that for number crunching, I mean really long running number crunching in scientific arena where the process is running for hours or days... in this case a 2x performance gain is GINORMOUS... if it is on a much smaller scale, then dynamic languages could still be of use.
To a large degree, programming language is a style choice. Use the language you want to use and you'll be maximally productive and happy. If for some reason that's not possible, then hopefully your ultimate decision will be based on something meaningful, like a platform you have to run against or real, empirical performance numbers, rather than someone else's arbitrary style choice.
Video card device drivers
Speed is typically the primary answer. Though this is becoming less of an issue these days.
when speed is crucial. Dynamic languages are getting faster, but still not close to the performance of what a compiled language is.
Interop is absolutely possible with dynamic languages. (remember classic visual basic, which has "lazy binding"?) It requires the COM component to be compiled with some extras though for helping their callers to call by name.
I don't think that number crunching has to be statically compiled, most often it is a matter of how you solve. Matlab is a good example made for number crunching, and it has a non-compiled language. Matlab, however, has a very specific runtime for numbers and matrices.
I believe you should always opt for statically-typed language where possible. I'm not saying C# or Java have good static systems but C# is getting close. Good type inference is the key because it will give you benefits seen in dynamic languages while still giving you security and features of statically-typed ones. Problem solved - no more flamewars.
System level code for embedded systems. A possible problem is that dynamic languages sometimes hide the performance implications of a single easy looking statement.
Like say this Perl statement:
#contents = <FILE>;
If FILE is a few megabytes, then that is one resource-consuming statement - you might exhaust your heap, or cause a watchdog timeout, or generally slow down the response of the embedded system.
If you want to "program closer to the metal", you probably want to be using a statically typed and "middle level" language.
How about interop? Is it possible to call a COM component from Ruby or Python?

Resources