Go to Post Pro: Very easy to build with. Con: HEAVY AS ELEPHANTS - Tetraman [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-06-2010, 10:59
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Non Strict Variables

Hello

In c++ (used sparingly), I borrow a part of Justin J. Meza's Lolcode compiler code so I can use Non-Strict variable typing. It is a struct abuser, but it works.

How can I get the equivalent in Java?

(ignoring the FUNKSHUNZ and BUKKITS, of course)
Attached Files
File Type: h loltypes.h (14.5 KB, 38 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 14-06-2010, 23:02
timothyb89 timothyb89 is offline
code monkey
FRC #1977 (Loveland High Robotics)
Team Role: Alumni
 
Join Date: Oct 2008
Rookie Year: 2009
Location: Loveland, Colorado
Posts: 45
timothyb89 will become famous soon enough
Re: Non Strict Variables

By design, Java doesn't really support untyped/non-strict variables. The closest you can come with "plain old Java" is something like this:
Code:
Object aString = "Hello, world.";
System.out.println(((String) aString).toUpperCase());
'Object' works fine as a generic container, but you'll have to typecast before calling any functions.

If you're writing for the cRIO that's probably about all you can do without any extra libraries due to the lack of reflection support. But for desktop Java (version 1.5 and up) you can pretty happily use Groovy, Jython, or any of the other languages that run natively on the JVM (JavaScript, BeanShell, JRuby, etc).

For the cRIO, though, you could likely use an old version of Groovy (or any other sufficiently old JVM-based scripting language) to build for JDK1.3. Languages this old are precompiled into standard bytecode and shouldn't have problems running on older versions of the JVM.

Even so, there might be a better way to accomplish things than with untyped variables, depending on what you're trying to do.
__________________
FRC-DB: A detailed, web-based scouting database for FRC teams with lots of interesting statistics.
Reply With Quote
  #3   Spotlight this post!  
Unread 15-06-2010, 08:05
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Non Strict Variables

You can approximate weak typing in Java by creating a class or interface that encompasses your entire domain of types of interest. For example, see the J2SE Number class. At the highest level, Object does this (except for built-in types like int, double, etc.)

In general, though, if weak typing is a requirement, Java is probably not the right tool for the job.
Reply With Quote
  #4   Spotlight this post!  
Unread 15-06-2010, 10:46
buchanan buchanan is offline
Registered User
FRC #2077 (Laser Robotics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2007
Location: Wales, WI
Posts: 67
buchanan is just really nicebuchanan is just really nicebuchanan is just really nicebuchanan is just really nice
Re: Non Strict Variables

I don't see anything here that couldn't be translated pretty much directly to Java:
  • The various data types become classes: structs become new classes, double, int, etc become Double, Integer...
  • In the value class, the void* becomes Object, the enum type becomes Class, the value* becomes an object reference to the parent instance of the same class.
  • Casts, methods, etc stay almost the way they are.
  • Mallocs become new Whatever, frees go away.
This would look very odd in Java, and one suspects the problem being solved, whatever it is, could be addressed in a more idiomatic way (interfaces, as mentioned, come to mind), but unless I'm missing something the code could be ported almost as is.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strict enforcement of Trailer Hitch rules? Chath Maral Rules/Strategy 2 17-01-2009 12:15
auton variables sirbleedsalot Programming 4 26-03-2005 14:24
Static Variables amateurrobotguy Programming 8 04-03-2005 00:40
Strict or loose interpretation? Wetzel Rules/Strategy 2 08-05-2002 20:21


All times are GMT -5. The time now is 11:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi