473,625 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What purposes do types serve?

I'm carrying on a discussion in a nother context regarding the value and
usefulness of data types. Part of that discussion has to do with how data
types might be implemented in the language specific to that context. I'm
using C++ as an example for comparison and contrast.

I believe I have a pretty go idea how data types work in C++, but I'm not
sure I could enumerate a list of reasons for using types without giving it
a lot of thought. Anybody care to provide their list of reasons for having
data types in C++?

--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Dec 4 '05 #1
2 1388
Steven T. Hatton wrote:
I'm carrying on a discussion in a nother context regarding the value and
usefulness of data types. Part of that discussion has to do with how data
types might be implemented in the language specific to that context. I'm
using C++ as an example for comparison and contrast.

I believe I have a pretty go idea how data types work in C++, but I'm not
sure I could enumerate a list of reasons for using types without giving it
a lot of thought. Anybody care to provide their list of reasons for having
data types in C++?


All data has a "type". The question is wether it is known by the
compiler ( "static type" ) and wether the compiler would be able to do
things better.

This is probably not an exhaustive list of "static type" usage.

a) Probably the most important use of types is that the compiler can use
it to create code that runs well (fast) on the target CPU. If you
didn't have any types then all objects would be the same and you would
need to determine type at runtime which can be prohibitibely costly from
a performance perspective. In theory, a dynamically typed system could
generate code at run time (JIT or Just In Time compiler). In practice
there are significant limitations in applicability. No JIT system is as
universally applcable as the more common statically typed compiler
implementations . For example, simple commands like "ls" or "cp" would
need to load a whole VM in Java and by the time the JIT compiler was
loaded it would be time to exit the process. Arguably, the JIT compiler
may produce better code for tight loops, however there is nothing
stopping the JIT process to work on compiled code as well (see valgrind
for example). Enough ranting - at least with the most common
dynamically typed languages today (javascript, php, perl etc), JIT is
not even an option.

b) selection of methods based on type. (function overloading)

c) specialization of code (generic programming based on templates)
Actually the whole idea of templates is that the type is still
determined at compile time but later than "parsing" time. It breaks the
compilation process into 2 logical phases, interpret the meaning of the
source code, generate the specializations needed and then generate the
final machine code. (The template "export" concept breaks that down even
further)

d) Error detection (oops probably ties as most important). One of the
most important things when designing code is that you want to make it so
that programming errors are found as soon as possible. This means that
you want to catch errors like ( apples > oranges ) comparing
incompatible types. In a dynamically typed system you may find these
errors at the most unfortunate time. (I can attest to that - I recently
fixed a bug in PHP where a certain comination of inputs would cause this
to happen - in a statically compiled system, these errors are found
before getting to this ).

Off the top, I can't think of anything else where a "dynamicall y typed"
programming system would be different to a "statically typed"
programming system.
Dec 4 '05 #2

"Steven T. Hatton" <ch********@ger mania.sup> wrote in message
news:js******** *************** *******@speakea sy.net...
I'm carrying on a discussion in a nother context regarding the value and
usefulness of data types. Part of that discussion has to do with how data
types might be implemented in the language specific to that context. I'm
using C++ as an example for comparison and contrast.

I believe I have a pretty go idea how data types work in C++, but I'm not
sure I could enumerate a list of reasons for using types without giving it
a lot of thought. Anybody care to provide their list of reasons for
having
data types in C++?


I assume you mean built-in types? Well, you need at least *one* data type:
the byte (or whatever term you want to specify as the minimum storage unit).
But adding more built-in types allows the code to operate faster, both
because you don't have to spend time reading part of a data item in order to
determine how to interpret the rest of it (as you do in XML, for example),
and also because you can use existing CPU instructions, which have integer,
floating-point, and byte operations (as well as possibly others).

Or perhaps you're referring only to user-defined types? In that case,
they're not actually _needed_ at all. But if you want to work in an
object-oriented language, in order to gain its benefits, then user-defined
data types are obviously required (by the definition of object-oriented).

If you mean why have _any_ data types at all, then I would posit that it's
impossible to present an algorithm which does not, by its very nature,
describe at least one data type (even if only a single "bit", to represent
the simplest, boolean, state).

-Howard
Dec 5 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18990
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
56
3723
by: Xah Lee | last post by:
What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that }
21
1594
by: godwin | last post by:
Hi all, I wanna thank Martin for helping out with my ignorance concerning execution of stored procedure with python. Now i have decided to write a web app that googles into my companies proprietary database. I need to know whether zope is good for that job. But even the introduction to zope in the zope book was intimidating. Are there any simple options? If so plz tell me how i can obtain it and study it. I should say that i am new to web...
121
10011
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
51
4501
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
13
5032
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
669
25819
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
21
2376
by: Osiris | last post by:
suppose I wanted to make availble on the WWW a facility to do some rather floating-point-calculation-intensive stuff. I can do that in PHP, but then all work must be done on the hosters' computer and PHP is SLOOOOOW. Compiled stuff would be much faster, but no commercial hoster would allow LAPACK stuff running on his machines. In what way could java be of help ? Are there hosters that allow my java stuff running on their machine and...
11
5119
Dormilich
by: Dormilich | last post by:
Lately I have seen so much awful HTML, that I like to show what a HTML document should look like, regarding the requirements from the W3C. the absolute minimum is defined as: or expressed in code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>My first HTML document</TITLE>
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6116
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.