how exactly is code defined? How is it distinct from law?
The word "code" means a comprehensive and logically organized statute. They are one kind of law.
A "code" can have subparts that are also called codes. For example, the codification of all of the laws in the state of Colorado is called the "Colorado Revised Statutes", but within the Colorado Revised Statutes are large, comprehensive statutes like the Uniform Commercial Code, the Probate Code, the Trust Code, and the Penal Code.
Shorter statutes enacted on a piecemeal basis are sometimes called "acts" rather than "codes" although there is no formal dividing line between the two. The only legal distinction between a code and an act is that the provisions of a code are expected to use words defined in the same way and to be internally consistent to a greater degree. Different acts can use the same words with different meanings, and all acts aren't intended to be read as a comprehensive whole in terms of how they are interpreted in isolation.
The U.S. federal government and U.S. state governments have a particularly low share of their laws in the form of comprehensive codes compared to most other countries.
In the U.S., many "codes" are drafted by private non-profit organizations as a model for governments to enact, and then adopted with minor local modification, by state or local governments.
The world's earliest known legal code: The Reforms of Urukagina, Sumeria. (2500 - 2350 BC)
Is code in the context of building and construction defined
differently from code as in, for example, the U.S. Code?
Not really.
The U.S. Code consists of the permanent statutes of the United States Congress organized in a subject matter fashion, and a building code is a well organized statute governing how structures are built.
In most U.S. states, building codes are adopted as local ordinances by county or municipal governments, generally adopting a particular version of a uniform building code promulgated by a private non-profit organization of building inspectors, with minor local modification.
In some U.S. states, however, they are adopted by the state government, or the state government enacts guidelines for how local governments could adopt them.
A municipal code consists of all the permanent ordinances of a city arranged on a subject-manner basis and would include the building codes adopted by the municipality.
The term ordinance refers to a statute adopted by a local government. The term statute refers to a law adopted by a legislative body like Congress, a state legislature, a county commission, or a city council, but in the case of statutes adopted by local governments, the term ordinance is preferred for clarity.
It is useful for building codes to be enacted as local ordinances because building codes are normally administered by local governments, and this facilitates enforcing building codes in municipal courts which are convenient for the local government and have judges that they typically appoint themselves.
what is the extent of building code and to what is it subject
hierarchically? Is it the Constitution --> federal law --> state law
--> building codes or does it go hand-in-hand with state law?
All laws in the U.S. are subordinate to the U.S. Constitution.
Federal law in the U.S. is supreme over state law in areas where the federal government is constitutionally permitted to, and has, legislated. Federal regulations are also supreme over state law in the constitutional supremacy sense.
The U.S. Constitution establishes a federal government that is, in principle, a "limited government", which can only legislate on specified topics subject to limitations like the Bill of Rights contained in the U.S. Constitution. In practice, there are few subjects that are beyond the legislative authority of the federal government, however, and the division between what is federal law and what is state law is more customary and political than it is a constitutional matter.
One of the reasons that lots of kinds of law is left to the states is that this deprives the federal courts of jurisdiction over these areas of law most of the time. The vast majority of civil and criminal cases are handled in state courts, rather than in federal courts.
As explained at Wikipedia:
For example, in Colorado, roughly 97% of all civil cases were filed in
state courts and 89% of the civil cases filed in federal court were
bankruptcies in 2002, a typical year. Just 0.3% of the non-bankruptcy
civil cases in the state were filed in federal court. . . .
As of 2019,
about 1,255,689 people currently behind bars in the United States—or
87.7% out of a total of 1,430,805 prisoners—had been convicted in state court for violating state criminal laws, rather than in federal
court for violating federal criminal laws.
The proportion of criminal cases brought in state court rather than
federal court is higher than 87.7% because misdemeanor and petty
offense prosecutions are disproportionately brought in state courts
and most criminal prosecutions involve misdemeanors and petty
offenses.
The number of trials conducted in each system is another way
to illustrate the relative size of the two criminal justice systems.
In Colorado, in 2002, there were approximately 40 criminal trials in
federal court, and there were 1,898 criminal trials (excluding
hundreds of quasi-criminal trials in juvenile cases, municipal cases
and infraction cases) in state courts, so only about 2% of criminal
trials took place in federal court. Most jury trials in the United
States (roughly five out of six jury trials conducted in any U.S.
Court) take place in criminal cases in state courts.
At a constitutional level, vis-a-vis the federal government, state constitutions, state law, and local ordinances are all "state law". But within states, state constitutions are superior to all state and local laws, and state laws have priority over local laws except for the state constitution provides otherwise (e.g. in the case of "home rule cities" in areas where local control is granted).
State government legislative power is in principle "plenary" in that it can legislate on any matter not contrary to the U.S. Constitution, validly enacted federal laws, or the state's constitution. States can enact laws on any matter it is not specifically prohibited from enacting laws regarding. In practice, however, the U.S. Constitution, federal laws and regulations, and state constitutions significantly constrain how states may legislate.
Of course, generally, state law is only applicable to matters connected to that state, and local law is only applicable to matters connected to the local government and its territory.
As far as I can understand the building code itself as set out by the
Constitution is fully determined by the States but within a State
there may also be municipal code. There also seem to cases such as NYC
and Chicago where they have their own code and are not subject to
State code. Anyways, you can see my confusion on the subject.
You are indeed confused and everything in the paragraph above is utter gibberish. Basically, the federal government has both a U.S. Code and the Code of Federal Regulations (which is a collection of federal regulations organized by subject-matter). Every states has a state code and often its own code of state regulations. Almost every county or municipality (a term that means city, town, or village) has its own code of ordinances and in larger cities sometimes a code of local regulations as well.
As a bonus, if someone could also explain regulations and how they tie
into code.
A regulation is an interpretation or elaboration of a statute enacted by an executive branch official (the President, the Governor, the Mayor) with the force of law, to the extent that it does not contradict the statute authorizing it.
Building codes are typically so specific that only a few regulations or supplementary ordinances (e.g. adopting the forms to be used in building permits and fee schedules for various local government permits, or the hours of operation of the building permit office) are necessary in connection with them.
Also, courts at the federal level, and in most states, adopt their own rules of procedure, that govern how court cases are handled. Court rules are like regulations, but adopted by the judicial branch rather than by the executive branch.
Don't Forget Case Law
Also, just to be clear, constitutions, statutes, ordinances, and regulations are not the only form of law in the United States. We also have "case law" which includes as a subset the "common law." Case law can be modified by the courts over time under a principle known as stare decisis which means that precedents should be honored and followed but can be changed by the courts when change is appropriate. Precedents of higher courts are superior to precedents from courts that appeal to the higher courts.
When appellate courts made binding rulings on legal issues this creates a precedent that can be used as legal authority in future cases. Some case law interprets constitutions, statutes, ordinances, and regulations. But some case law just proclaims what the law is in a particular area without having any statutory basis, and the "common law" consists of all case law of this type.
In the U.S., most of the law of contract, torts (i.e. civil wrongs like the right to sue a careless driver who causes an accident for negligence), property, and agency is part of the common law, which in the U.S. is derived from English law at the time of the American Revolution, and has developed separate in each state, mostly as a matter of state law, since then. Historically, most criminal law was set forth as common law rather than as statutes, but in modern times, almost all criminal law in the U.S. is codified in statutes.
Most states have statutes that tweak the common law without comprehensively codifying the subject matter of the common law subject tweaked. For example, every state has a statute which sets forth the deadline for suing to enforce common law rights, called a "statute of limitations" without statutorily defining the underlying common law rights (except in Louisiana and Puerto Rico, and to a lesser extent, California, which do codify what would be the common law in other states).
This is relevant even to building codes. For example, one way to enforce a building code violation is by having a local government go to court and seek a permanent injunction against the builder. But the process and substantive standards for granting a permanent injunction are matters of court rules and case law. Likewise, the rules for interpreting building codes are set forth in case law.
Civil Codes Compared
Common law legal systems are shown in red, civil law systems are in blue, Islamic law systems are in green, yellow indicates contributions from local customary law, and other colors indicate hybrid systems such as purple for common law-civil law hybrids.
Countries with what are called "civil law legal systems" don't have any common law. The have civil codes instead of common law, which are all based upon the Napoleonic Civil Code enacted after the French Revolution. But other countries, such as Germany and Spain, enacted civil codes which are similar in concept, but different in structure, detail, and substance, from the French civil code.
Every law and regulation must be rooted in a statute enacted by a legislature in those countries. The bulk of their day to day law is codified in codes such as a "civil code" (and sometimes a "commercial code") that covers most of what the common law does in common law countries. The laws of Louisiana and Puerto Rico are based on the historic French and Spanish civil codes respectively. California's codes are a codification of the English common law with some concessions to the Mexican civil code (based upon the Spanish civil code) that was in place before it joined the United States. Many other U.S. states in the American Southwest (including Texas) also make concessions in their laws to the pre-existing Mexican civil code.
In Canada, the laws of Quebec are based on the French civil code and are fully codified.